Search code examples
jsonrestbitbucketbitbucket-api

Retrieve Text file content from Bitbucket


I want to Read the text file which is uploaded in BitBucket through REST Api.

URL: https://{username}:{token}/bitbucket.org/rest/api/1.0/{path}.

This gives JSON of folder content. I wanted to read text file and to extract the content. How to do it?


Solution

  • In term of API, make sure to not use the V1, which is deprecated for BitBucket.

    One API endpoint which returns the content of a file would then be /2.0/repositories/{workspace}/{repo_slug}/src

    If the path matches a file, then the raw contents of the file are returned (unless the format=meta query parameter was provided, in which case a json document containing the file's meta data is returned).

    If the path matches a directory, then a paginated list of file and directory entries is returned (if the format=meta query parameter was provided, then the json document containing the directory's meta data is returned).