Bitbucket cloud Tag creation via API fails with error - {"fields": {"target": "expected a dictionary"}

Hi All,

I am trying to create a tag for a hash in my bitbucket repository, but getting below response ,

{“type”: “error”, “error”: {“fields”: {“target”: “expected a dictionary”}, “message”: “Bad request”}}

Below is the end point and code,

url= https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/commits/

response=requests.post(url,data={‘name’: ‘tag_17112020_v1’, ‘target’: {‘hash’: hash_for_commit}},auth=auth_tuple)

Also I have tried below with headers as well,

response=requests.post(url,headers={‘Content-Type’: ‘application/json’},data={‘name’: ‘tag_17112020_v1’, ‘target’: {‘hash’: hash_for_commit}},auth=auth_tuple)

But the response is ‘Bad request’.

Could you please help me on this. Thanks in advance

Hey guys,

I have found the issue. I was sending the data as a dictionary. But for this endpoint we need to send it as json string like below,

data ="{“name”:“tag-name”,“target”:{“hash”:“commit-hash”}}"

Now , I can create the tag for the given hash through API :slight_smile: