Saving artifacts to Bitbucket Downloads from Windows runner

James Andrew
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 12, 2024

Having trouble using the approach provided here:

Deploy build artifacts to Bitbucket Downloads 

Running a Windows 10 VM with PowerShell 7.4.2.

This is the script I have tested:

$url = "https://api.bitbucket.org/2.0/repositories/${$BITBUCKET_REPO_OWNER}/${$BITBUCKET_REPO_SLUG}/downloads"

$pair = "{0}:{1}" -f ($BITBUCKET_USERNAME, $BITBUCKET_APP_PASSWORD)

$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)

$token = [System.Convert]::ToBase64String($bytes)

$headers = @{ Authorization = "Basic {0}" -f ($token) Accept = "application/json" }

$bin_file_path = "C:\Users\user\Documents\#21 Build Products.zip"

$form = @{ files = Get-Item -Path $bin_file_path }

$result = Invoke-RestMethod -Uri $url -Method Post -Form $form -Headers $headers

The response says "This endpoint does not support token-based authentication".

Screenshot 2024-06-12 225359.png

I have tried to re-create in PowerShell the example approach shown that uses the curl command, but without success.

I found a similar question raised here and the reply seems to suggest that basic authentication should work:

This endpoint does not support token-based authentication | Default reviewers 

I appreciate your help.

1 answer

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 16, 2024

G'day, @James Andrew 

Welcome to the community!

I am not an expert in PowerShell script, so I can't comment much, but I suspect you are using incorrect authorization; hence, it received your credentials as a token, which the endpoint does not support. So, as a start, review your script again and ensure it works locally and uses the correct authorization method.

That say, you mention that you've tried using curl but without success, can you let me know what was the error or issue you faced? 

Regards,
Syahrul

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events