Forums

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

using example, creating webhooks with API 400 bad reques

Christian Bongiorno
Contributor
August 20, 2019

Using their examples, adjust for my case, I get 400 bad request with no reason. Besides giving no feedback being bad API design, can someone explain what's up? Here, is a GET to prove the details of the repo followed by a POST to create a hook that fails. Can someone explain what's missing?

Straight from their docs:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/hooks

curl -u chb0bitbucket:apptoken "https://api.bitbucket.org/2.0/repositories/twengg/migrations/hooks?pagelen=1&size=1" 2> /dev/null | jq .
{
"pagelen": 1,
"size": 14,
"values": [
{
"read_only": true,
"description": "Jira",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/twengg/hooks/%7B755890ad-a8bc-4dd4-97c2-8d72036f1969%7D"
}
},
"url": "https://sterlingts.atlassian.net/rest/bitbucket/1.0/organization/webhook",
"created_at": "2019-07-12T01:20:23.382523Z",
"skip_cert_verification": false,
"source": "connect",
"history_enabled": false,
"active": true,
"subject": {
"username": "twengg",
"display_name": "Sterling",
"type": "team",
"uuid": "{1b6fda1d-32c1-4cb6-9e19-d662df20c277}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/%7B1b6fda1d-32c1-4cb6-9e19-d662df20c277%7D"
},
"html": {
"href": "https://bitbucket.org/%7B1b6fda1d-32c1-4cb6-9e19-d662df20c277%7D/"
},
"avatar": {
"href": "https://bitbucket.org/account/twengg/avatar/"
}
}
},
"type": "webhook_subscription",
"events": [
"repo:created"
],
"uuid": "{755890ad-a8bc-4dd4-97c2-8d72036f1969}"
}
],
"page": 1,
"next": "https://api.bitbucket.org/2.0/repositories/twengg/migrations/hooks?pagelen=1&page=2&size=1"
}

 

curl -v -X POST -u chb0bitbucket:apptoken -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/repositories/twengg/migrations/hooks -d '
{
"description": "Webhook Description",
"url": "https://jenkins1.dev.backgroundcheck.com/bitbucket-scmsource-hook/notify",
"active": true,
"events": [
"repo:push",
"issue:created",
"issue:updated"
]'

Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 18.205.93.6...
* TCP_NODELAY set
* Connected to api.bitbucket.org (18.205.93.6) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Atlassian, Inc.; OU=Bitbucket; CN=*.bitbucket.org
* start date: Jun 12 00:00:00 2017 GMT
* expire date: Jun 16 12:00:00 2020 GMT
* subjectAltName: host "api.bitbucket.org" matched cert's "*.bitbucket.org"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Server auth using Basic with user 'chb0bitbucket'
* Using Stream ID: 1 (easy handle 0x7faf6700a400)
> POST /2.0/repositories/twengg/migrations/hooks HTTP/2
> Host: api.bitbucket.org
> Authorization: Basic apptoken
> User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
> Accept: */*
> Referer:
> Content-Type: application/json
> Content-Length: 257
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* We are completely uploaded and fine
< HTTP/2 400
< server: nginx
< vary: Authorization
< content-type: text/plain
< x-oauth-scopes: pipeline:variable, webhook, snippet:write, wiki, issue:write, pullrequest:write, repository:delete, repository:admin, project:write, team:write, account:write
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< date: Tue, 20 Aug 2019 10:13:16 GMT
< x-served-by: app-143
< x-static-version: 818669ddc879
< etag: "825644f747baab2c00e420dbbc39e4b3"
< x-credential-type: apppassword
< x-render-time: 0.172693014145
< x-accepted-oauth-scopes: webhook
< x-version: 818669ddc879
< x-reads-before-write-from: default
< x-frame-options: SAMEORIGIN
< x-request-count: 109
< content-length: 11
<
* Connection #0 to host api.bitbucket.org left intact
Bad Request

 

1 answer

1 accepted

2 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 20, 2019

Hello @Christian Bongiorno,

Thanks for reaching out.

Besides giving no feedback being bad API design

You're right, we overlooked this particular case. Generally Bitbucket tries to return an explanation of what's wrong with the request. I'll see if I can fix this particular case.

Can someone explain what's up?

The payload you're sending is an invalid JSON, you missed the closing curly brace in the very end.

Cheers,
Daniil

Christian Bongiorno
Contributor
August 20, 2019

Daniil,

 

Thanks for the fast reply - I double checked, and, straight from your example, it's wrong. So, best to update your example too. 

 

BTW: There is no PUT/PATCH/DELETE - so, there is no programmatic way to fix a mistake. Should I cut a ticket elsewhere?

seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 20, 2019
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 20, 2019

Thanks for the fast reply - I double checked, and, straight from your example, it's wrong. So, best to update your example too.

Do you mean the API endpoint documentation page that you linked above? The example on that page looks good to me.

Bitbucket API 2019-08-21 00-33-18.png

Or did you mean something else?

Cheers,
Daniil

Like Daniel Eads likes this
Christian Bongiorno
Contributor
August 21, 2019

I stand down. :) Cheers. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events