I have a task in jira, and I want to use a automation rule.
With this rule I want to run a pipeline in bitbucket.
I create an oauth consumer in the repository, but when I generate an access token and make the post request I get and status code 500.
Hello @Mauricio Mondragon ,
Thank you for reaching out to Atlassian Community!
With regards to the call-back URL, it's only really needed if you are using an OAuth flow that involves a web browser. From my understanding, you are trying to build an automation in Jira that just involves API calls, so you can put any URL as the callback URL such as https://localhost or https://bitbucket.org, as it will not impact the token that will be provided.
Having said that, in order for us to investigate further I would need to have more information about what are the details of your API call :
Thank you, @Mauricio Mondragon .
Kind regards,
Patrik S
hi @Patrik S
Thank you for replying.
In my automation rule I´m send web request to this url
My headers are
Content-Type application/json
Authorization Bearer + token
I tried generating the token by client credentials and Authorization code, but the status response is 500 by this methods.
My body request is:
{
"target": {
"ref-type": "branch",
"type": "pipeline_ref_target",
"ref_name": "master"
}
}
I'm based on this documentation
In this documentation mentioned a basic authorization but with this type of auth I get this response:
Bitbucket Cloud recently stopped supporting account passwords for API authentication. See our community post for more details: https://atlassian.community/t5/x/x/ba-p/1948231 App passwords are recommended for most use cases and can be created in your Personal settings: https://bitbucket.org/account/settings/app-passwords/ For more details on API authentication methods see our documentation: https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication
If I use an app pasword I get this response:
* Basic <app_password>
400 "Invalid Authorization header"
* Bearer <app_password>
401
{ "type": "error", "error": { "message": "Access token expired." } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mauricio Mondragon ,
Thank you for providing more details.
I think the issue here is that you are not providing the correct authentication credentials to the API calls in your automation.
My suggestion here is that you use Oauth client credentials flow, so when you create an Oauth consumer under your workspace settings, you will be provided with a key and secret.
The automation would consist in two steps :
You need to call the access_token endpoint to get a Bearer token that will be used in the later step to call the actual Bitbucket API you are looking for. You need to configure the step in your automation as per the below example:
The parameters used are the following :
URL: https://bitbucket.org/site/oauth2/access_token Headers :
authorization : Basic <Base 64 encoded "key:secret"> Content-Type : application/x-www-form-urlencoded Body: grant_type=client_credentials
Please note that in the authorization header you have to provide the base64 encoded value of your OAuth key and secret. On mac you can base64 encode a string using the following command :
echo -n "KEY:SECRET" | base64
You need to use the access_token you got in the step above to authenticate the call to Bitbucket API endpoint you want, as the following example :
The parameters are :
URL: https://api.bitbucket.org/2.0/< Endpoint >
Headers :
Content-Type : application/json
Authorization : Bearer {{webResponse.body.access_token}}
Could you please try configuring as the suggestion above and check how it goes?
Thank you, @Mauricio Mondragon .
Kind regards,
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Patrik S
I followed your instructions and it works for my automation rule.
Now when I request run a pipeline I get a successful response.
Thanks for your help. This was very helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Mauricio Mondragon ,
You're very welcome!
Happy to have been of some help :)
Kind regards,
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.