Forums

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

Retrieve assets via API

Gediminas Kulys February 21, 2023

I need help on how to retrieve info of assets in JIRA cloud via API. The documentation well let's say probably I cant find it but I would say it needs to improve.

This is the code I'm using and every time I do according to documentation I can't find any assets

import requests
import base64
import json

# Set the Jira Cloud URL and your Jira account credentials
jira_username = 'username'
jira_api_token = 'token'

# Encode the credentials in base64 format
auth_str = f'{jira_username}:{jira_api_token}'
auth_b64 = base64.b64encode(auth_str.encode('utf-8')).decode('utf-8')

# Set the object ID of the asset object to retrieve
object_id = 23

# Construct the REST API URL for retrieving the asset object information
api_endpoint = f'{jira_url}/rest/assets/1.0/object/objectschema/list'

# Define the basic authentication headers with base64-encoded credentials
auth_headers = {
    'Authorization': f'Basic {auth_b64}',
    'Content-Type': 'application/json'
}

# Send a GET request to the API endpoint with the authentication headers
response = requests.get(api_endpoint, headers=auth_headers)

# Check if the request was successful and print the asset object information if it was
if response.status_code == 200:
    asset_object = json.loads(response.text)
    print(asset_object)
else:
    print('Failed to retrieve asset object:', response.status_code, response.reason)

0 answers

Suggest an answer

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

Atlassian Community Events