jirajira-rest-apipython-jira

activationID in JIRA Asset Management API


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" }


Solution

  • 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:

    1. Use basic auth to authenticate.
    2. Use the workspace call to discover your workspaceID
    3. Use the REST API with your workspaceID to make your REST API calls.

    There are a couple of issues in your code

    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=(",", ": ")
        )
    )