Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

PowerShell connection to Bitbucket V2 API Basic Auth

Deleted user October 25, 2018

I'm using PowerShell's Invoke-WebRequest applet to make a basic authenticated connection to the bitbucket REST API. I Want to get a json snippet file. 

Error Message: Access Denied.

__________________________________________________________________________________

$bitBucketUsername = "Email"
$bitBucketPassword = "XXXX"
$pair = "$($bitBucketUsername):$($bitBucketPassword)"

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"

$response2 =

Invoke-WebRequest

-Method Get

-Uri 'https://api.bitbucket.org/2.0/snippets/UserID/EncodedID/files/XX.JSON'

-Headers @{ 'Authorization' = $($basicAuthValue)}
_________________________________________________________________________________

I also tried generating a PSCredential Object but it's not working.

If a try to connect to the API via Postman using my $basicAuthValue as an Authorization Header seems to be working fine, so it make me guess that the issue is the connection with powershell and not how I'm generating my credentials.

 

1 answer

0 votes
Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2018

we use this poweshell module. takes care of most of the interaction with the Atlassian tools:

 

https://atlassianps.org/module/BitbucketPS/ 

Deleted user October 26, 2018

Hi, thanks for your answer.

 

It says: Page not found

Do you have access to the readme file?

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2018

looks like i pasted the url  with an extra space ... you can either click or copy paste the URL

 

https://atlassianps.org/module/BitbucketPS

Deleted user October 26, 2018

Thanks. I've got the project now, but on the Readme file - installation part is empty.

How can I add it to my project?

Deleted user October 26, 2018

I found it, thanks

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2018

Install the module:

Install-Module BitbucketPS

 

Import in you PS script:

Import-Module BitbucketPS
Deleted user October 26, 2018

Sorry but when I try to do 

Install-Module BitbucketPS

I'm getting an error, It says no Match was found for the specified search criteria. Also I can't find the BitbucketPS module in PsGallery website. I only found "PS.Bitbucket".

Like Ilya I_ likes this
Ilya I_
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!
November 29, 2018

@Krishnanand Nayakhi. There is no such known Module for Powershell in PS Gallery, with the name you have provided - 'BitbucketPS'491f2-clip-17kb.png

Either it is removed/revoked, or it have never existed. Or there is an additional module source, that need to be added.

Could you please provide a valid link to the module or answer an initial question, how to correctly connect to BitBucket using Powershell - either API or standard Invoke-RestMethod?

 

Thanks a lot for answer (i hope it will happen).

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 29, 2018

did you go to the URL that i mentioned above?

i don't own that PS module so if the module is not present in the gallery, you might want to reach out to the group who maintains it.

If you search the gallery, there are other bitbucket modules, have you tried them?

Ilya I_
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!
November 29, 2018

Yes i tried, there is nothing about installation.

I found some in PS Gallery, but none of those modules met my requirements/needs.

 

P.S. Did you try to install this module by yourself on a clean machine, before supposing it to others?

 

Thanks.

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 29, 2018

I am user of their other modules, hence i recommended. If none of the solutions work then here is an opportunity to build one :)

 

and the answer to the other question is No, i use their other modules and hence recommended. Di you try reaching out to atlassianps team?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events