Forums

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

Response 500 from trying BitBucket 'update pull request' api call to change title

Anthony Nguyen
Contributor
October 29, 2024

https://api.bitbucket.org/2.0/repositories/{workspace}/{repo-slug}/pullrequests/{pull-request-id}

{

    "title": "{new title}"

}

 

The above is the call from Jira automation. I am getting response 500, "something went wrong," which is too vague to give me any clues. I can do get pull request fine. Authentication is being done through app password with all pull request options checked.

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 1, 2024

Hi Anthony,

I checked the error code you provided in the other question here, but I couldn't find this error code in our system.

You said you are making this API call from Jira automation. We will need some additional details to reproduce the error and find out what causes it.

1. What is the trigger of this automation rule?

2. What is the action in the automation rule that performs this API call? Is it a Send web request?

3. If so, can you please hare some details, like:

  • In the Web request URL, do you provide a hard coded URL like
    https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/32

    or are you using smart values in the URL?

    If you are using smart values, what does the URL look like?

  • Is the HTTP method PUT?

  • For the Web request body, have you selected Custom data, and does the data look like this:
    {
    "title": "Some new title"
    }

  • In the Headers, have you added the following ones, apart from the Header for Authorization?

    Key: Accept Value: application/json
    Key: Content-Type Value: application/json

Kind regards,
Theodora

Anthony Nguyen
Contributor
November 1, 2024

Hi Theodora,

First, thank you for responding to my question. Here is the requested information. Please let me know if I was too vague for any portion, and I'll do my best to provide further detail.

1. It was originally triggered when the issue transitioned to "Deployment Assurance." Afterwards, I used the "validate" option in the "Send Web Request" interface to test and reproduce the problem.

2. Yes, it's "Send Web Request."

3. I am using smart values. The URL is "https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/{{pullRequest.id}}." pullRequest here refers to a pull request I previously retrieved using "get pull request." When trying the "validate" option, I used a hard coded URL instead, but as mentioned, the problem persisted.

I am using PUT, and yes, the custom data is following that format.

Yes, all the headers have been added as specified by "update pull request."

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 4, 2024

Hi Anthony,

Thank you for the details.

This part is a bit unclear to me:

I am using smart values. The URL is "https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/{{pullRequest.id}}." pullRequest here refers to a pull request I previously retrieved using "get pull request." When trying the "validate" option, I used a hard coded URL instead, but as mentioned, the problem persisted.

 

  • Do you have another "Send Web Request" action, before the "Send Web Request" that tries to update the PR title?

  • Can you please provide the exact steps you followed to create the {{pullRequest.id}}?

  • In the "Send web request" action that tries to update the PR title, have you tried using a hard-coded PR ID? So, instead of {{pullRequest.id}} use the ID of a specific PR. Does this also fail?

  • If you execute a curl command like the following from your own computer in order to update a PR's title, do you get a "Something went wrong" error as well?
curl -u username:app-password --request PUT \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/23' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"title": "Some new title"
}'

In bold are the values you need to replace with your own. I am asking this so we can narrow down if the issue is specific to the Jira automation rule or not.

Additionally, if you get any new error codes along with the 500 error (either from the automation rule or with curl), can you please provide them, just in case I get results in our system for the new error codes?

Kind regards,
Theodora

Like Anthony Nguyen likes this
Anthony Nguyen
Contributor
November 6, 2024

Hi Theodora,

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 8, 2024

Hi Anthony,

Thank you for the details!

I've had some results with the error codes you provided and I was able to reproduce the exact same error when the header Content-Type in the automation rule's Send web request action has one or more uppercase letters in its value.

So, Content-Type application/json in the automation rule will work, but Content-Type Application/JSON will result in a 500 error; the error code I get then shows the same error message as your codes.

Can you check if there any uppercase letters in the value application/json for the header Content-Type, and if so, replace them with lowercase?

I suggest to try this first with an action that has a hard coded PR id, so we can see if that solves the most basic approach.

Kind regards,
Theodora

Like Anthony Nguyen likes this
Anthony Nguyen
Contributor
November 8, 2024

Hi Theodora,

That's a great find. Indeed, the headers were using Application/JSON. I changed them to application/json for the bare minimum single action with the hard coded PR ID, and now it is functioning. It seems case sensitive which is strange; I wonder if it's just for that? Thank you for your help.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 11, 2024

Hi Anthony,

The uppercase in that header's value is an issue, but we can't rule out that there are other issues if there are still failures with the PR whose ID is not hard-coded.

Do you still get an error when you use the following in the Web request, after fixing the header values?

https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests/{{pullRequest.id}}

If so, what kind of error do you get?

Kind regards,
Theodora

Anthony Nguyen
Contributor
November 11, 2024

Hi Theodora,

I am not getting any errors anymore, with either hard-coded or smart values! Is there anything else I should check?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2024

Hi Anthony,

That's good to hear, thank you for the update!

Without seeing what exactly you are doing in this part:

I execute "get pull request" with https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/pullrequests?q=state%3D%22open%22%20AND%20title~%22{{issue.key}}%22&fields=values.title,values.id. Delay actions until done is checked. From there, I perform advanced branching off {{webResponse.body.values}} with entries named "pullRequest" hence {{pullRequest.id}}.

it's hard to say if there's anything else to check. If it works, I assume the rule is ok. Otherwise, I would need the exact steps to recreate that part of the rule and see if it is ok.

Another thing to keep in mind is that a merged or a declined PR cannot be updated. So, if your request returns the ID of a merged or declined PR, the update will fail.

Kind regards,
Theodora

Anthony Nguyen
Contributor
November 12, 2024

Hi Theodora,

I believe it should be fine as I am filtering for open pull requests only. I was curious though, is the case sensitivity with application/json a bug and if so, one that will be addressed? I've used both styles across various other API calls (Confluence, Jira, and BitBucket itself).

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 15, 2024

Hi Anthony,

I discussed this with the development team and it is indeed a bug. I created a bug report in our issue tracker:

You can select the link This affects my team in the bug report to indicate you are affected by this issue. You can also add yourself as a watcher (by selecting the Start watching this issue link in the bug report) if you'd like to get notified via email on any updates.

We don't provide ETAs and bug fixing is done as per our policy here.

Please feel free to reach out if you have any questions.

Kind regards,
Theodora

Like Anthony Nguyen likes this
Anthony Nguyen
Contributor
November 15, 2024

Thanks for the help, Theodora!

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 18, 2024

You are very welcome, Anthony! Please feel free to reach out if you ever need anything else!

Like Anthony Nguyen likes this

Suggest an answer

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

Atlassian Community Events