I'm working with Jira Asset Management API have the following code to fetch an object.
import requests
import json
id = "<validobjectid>"
url = "https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/object/{id}"
headers = {
"Accept": "application/json",
"Authorization": f"Basic {encoded_credentials}",
}
response = requests.request("GET", url, headers=headers)
print(
json.dumps(
json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
)
)
However I'm receiving a 400 error . I'm using the API token I generated under the security section in this method .
I'm not sure what is this activationID . Any help will be helpful
{ "code": 400, "message": "activationId is not provided" }
According to the official documentation:
Assets REST API Guide
The Standard Assets REST API Guide will walk you through a workflow that is designed for users that want to use the REST API to complete tasks other than importing data or data structures into Assets. It follows the normal procedure of making REST API calls using basic auth.
This workflow includes the following steps:
- Use basic auth to authenticate.
- Use the workspace call to discover your workspaceID
- Use the REST API with your workspaceID to make your REST API calls.
There are a couple of issues in your code
workspaceId
variable is not defined, you can discover it by following the official docsf
for an f-string before the quotes "
A corrected and tested version of your code would be
import requests
import json
workspaceId = "<your_workspace_id>"
id = "<validobjectid>"
url = f"https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/object/{id}"
headers = {
"Accept": "application/json",
"Authorization": f"Basic {encoded_credentials}",
}
response = requests.request("GET", url, headers=headers)
print(
json.dumps(
json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
)
)