Importing Raw Text File into Power BI
Asked by Luke D_Anastasi:

Hi,

I am trying to import a raw text file from a repo I have in bitbucket into power bi, but I get a file note found. Once I import this file, I want to evaluate the query ( I know how to do this) but I can't get access to the text file.

Can anyone tell me what syntax I need?

```
let
// Define the URL of the API endpoint
url = "https://bitbucket.org/broadspectrum/bustthetape/raw/7f104785464107f192272d47c30cf2766c57ea13/70061.txt",

// Set up the HTTP headers to include the Bearer token
headers = [
#"Authorization"="Authorization: Bearer Token"
],

// Get HTML content from the API
Source = Text.FromBinary(Web.Contents(url, [Headers=headers])),

// Example of parsing HTML content:
// This is a simplistic example where we look for a specific tag or pattern.
// This will need to be adjusted based on the actual HTML structure you're dealing with.
startIndex = Text.PositionOf(Source, "<tag>"),
endIndex = Text.PositionOf(Source, "</tag>"),
extractedValue = Text.Middle(Source, startIndex, endIndex - startIndex + 5) // Adjust length based on tags

// More complex parsing might be needed based on the HTML structure
// You might also need to split the text, extract parts using Text.BetweenDelimiters, etc.
in
extractedValue
```


Answers:
author: Syahrul
body: G'day, [@Luke D_Anastasi](/t5/user/viewprofilepage/user-id/5478610)

Welcome to the community!

I believe you can't use the direct URL raw files if you are making an API request. You should use the following example:

```
https://api.bitbucket.org/2.0/repositories/<Workspace>/<Repo>/src/<commit>/<filepath>
```

Do note that you are required to log in with username app_password to authenticate.

Regards,  
Syahrul

comments: author: Luke D_Anastasi
body: Thanks Syahrul, can't I add an api token to the address to authenticate?

How would the syntax look like?

I literally just want to import the code I have in the text file, so I can then evaluate those instructions in Power Query.

Using a the RAW URL with Git works, but bitbucket I get a 404.


author: Syahrul
body: Hey [@Luke D_Anastasi](/t5/user/viewprofilepage/user-id/5478610)

I'm not an expert on Power Query, so I can't offer much help in that area. However, I can provide you with an example of how to obtain files using Curl:

```
curl -X GET -u <username>:<app_password> https://api.bitbucket.org/2.0/repositories/<Workspace>/<Repo>/src/<commit>/<filepath> --output file.csv
```

If you wish to use Token, please check our documentation on how to generate tokens and use them at:

<https://developer.atlassian.com/cloud/bitbucket/rest/intro/#repository-access-tokens>

For example, using a Repository access token:

<https://support.atlassian.com/bitbucket-cloud/docs/using-access-tokens/>

Regards,  
Syahrul


author: Luke D_Anastasi
body: Power BI cannot deploy cURL commands.

Is there way I can do this via the REST API?


author: Syahrul
body: Hey [@Luke D_Anastasi](/t5/user/viewprofilepage/user-id/5478610)

Noted. If that's the case I suggest asking this type of question directly on our community developer page at:

<https://community.developer.atlassian.com/c/bitbucket-development/12>

Regards,  
Syahrul


Tags: bitbucket-cloud

cloud

powerbi