Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to find an Jira assets object id based on some attribute like email or username via API call?

Wendy Wei May 30, 2024

Hello,

I need to update a jira user object under assets via API call.  How do I find the user object id based on username or email via API call?

Any suggestion or idea is highly appreciated.

Thank you

Wendy

1 answer

0 votes
Gikku
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2024

@Wendy Wei Below steps should get you accomplish the requirement.

  1. Use the AQL api Post object aql to first retrieve the asset object to be updated
    The AQL query should specify the object schema and object type to be searched for, along with the attributes to be matched (username or email)
  2. Once you have the object returned, use the objectKey value to update the object via Put object {id} API.
Wendy Wei May 31, 2024

@Gikku thank you for the information. However, I cannot get expected result using below url, it still retrieve 25 users as pageObhectSize, not just the specific one:

https://api.atlassian.com/jsm/assets/workspace/XXXXXXXXX..../v1/aql/objects?qlQuery=objectschemaId=4&objectTypeId=6&username="Wendy.Wei@xxx.com".  In addition, i got 405 method not allowed error when using either post or put.  but using Get does return results, just not a single result.  

Any idea?

Wendy Wei May 31, 2024

@Gikku any suggestions?

thanks,

Wendy

Gikku
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 4, 2024

@Wendy Wei The query should be corrected as 'objectSchemaId' and you can also verify the results by running the same search from the UI to see if you are getting the intended results. 

Here is a sample code that I am using with Scriptrunner.

*******

def ASSETS_WITH_TAGS_AQL = 'objectSchemaId=1 AND objectTypeId=2 AND Tag IS NOT EMPTY'

def getDevicesWithUsername = {
post("https://api.atlassian.com/jsm/assets/workspace/${WORKSPACE_ID}/v1/object/aql?maxResults=10&includeAttributes=false")
.basicAuth(ASSETS_ACCOUNT, ASSETS_TOKEN)
.header('Content-Type', 'application/json')
.body([qlQuery: "${ASSETS_WITH_TAGS_AQL}"])
.asObject(Map)
.body
.values as List
}

Wendy Wei June 5, 2024

@Gikku 

thank you very much for your information. I was able to use below to retrieve the specific object using label, instead of username.

However, I am having issue with create an asset object using below:

https://api.atlassian.com/jsm/assets/workspace/xxxxxx/v1/object/create, i am getting 401 unauthorized error but it wa confirmed the user making the connection does have write permission.  I am not sure exact what parameters I should be using.  is basic authorization correct? useraccount: password? or username: apitoken when making connection?

 

thank you very much!

 

Wendy

Like Gikku likes this
Gikku
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 5, 2024

@Wendy Wei Try using the API token for the script. Basic auth is fine. 

Wendy Wei June 5, 2024

@Gikku 

I tried to use:

username:APItoken

then applied base64 code on this string, and use it on header as:

Authorization: Basic base64encoded of username:APItoken

Content-Type: application/json

still threw 401 error.

anything else I am missing?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events