Forums

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

How to set Asset object field when creating JSM ticket

Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2025

[!! SOLVED BELOW !!] Using the API Post to rest/servicedeskapi/request, (docs) I can insert a JSM ticket, but when trying to set an asset object, it fails with a 400 (There was an error parsing JSON. Check that your request body is valid). The custom field (16353) is backed by the JSM Asset object and is on the create screen. 123456 would be my workspaceId and objectId 49 is the correct asset object value I want to set this field to.

{
"serviceDeskId": "16",
"requestTypeId": "17",
"requestFieldValues": {
"summary": "Summary here",
"description": "Descr here"
"customfield_16353": [
{
"workspaceId": "123456",
"Id": "123456:49",
"objectId": "49"
}
]
}
}

I also tried this approach with the same error.

 

{
"serviceDeskId": "16",
"requestTypeId": "17",
"requestFieldValues": {
"summary": "Summary here",
"description": "Descr here"
"customfield_16353" : [{"id": "123456", "objectId": "49", "workspaceId": "123456"}]
}
}

3 answers

0 votes
Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 14, 2025

I found my problem. While I expose this customField on the 'Issue View' page of the RequestType, it is not exposed on the 'Request Form' so it is not available on insert which is why the API fails. I'll have to come up with some means to hide this field on the portal page or maybe use a different issueType altogether that we can call through an API only.

Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 14, 2025

I found a more eloquent solution to simply insert the JSM ticket first and then update the custom asset-backed field. I was doing it wrong above; here's the solution. I chose this route since the business doesn't want these two asset-backed fields on the request form on the portal and instead of building another requestType just for an API, this makes more sense to us.

And for clarity for others, call these APIs to retrieve some of these parts if a reader gets here and is still struggling.

--get workspaceId

GET: rest/servicedeskapi/insight/workspace

--get serviceDeskId

GET: rest/servicedeskapi/servicedesk

--get requestTypeId

GET: rest/servicedeskapi/servicedesk/{serviceDeskId}/requesttype

And to get your objectId, I cheated and went to the asset value in question and observed the URL.

And to get your customfield's ID, I cheated and went to the custom field's contexts and observed the URL.

 

--insert the JSM work item

POST: rest/servicedeskapi/request

{
"serviceDeskId": "16",
"requestTypeId": "17",
"requestFieldValues": {
"summary": "Summary here",
"description": "Descr here"
}
}

--circle back and update the JSM work item

PUT: rest/api/3/issue/{jiraKey}

{
"fields" : {
"customfield_16353": [{
"id": "123456:31093",
"objectId": "31093",
"workspaceId": "123456"
}],
}
}

0 votes
Marc - Devoteam
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 14, 2025

Hi @Paul Alexander 

Check this article, how-to-create-issues-with-assets-custom-field-using-jira-service-management-api 

This should provide the right json, I see you already use this right config.

The error message stated that the custom field is no available for the request type you want to use.

Is this field specified in the request type when an issue is created via the jsm portal, if not, this is why you get this error.

0 votes
Christopher Yen
Community Champion
April 11, 2025

Hi @Paul Alexander , I think you're missing a comma after description which could trigger the error parsing JSON

2025-04-11 15_32_44-How to set Asset object field when creating JSM ti....png

Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2025

That missing comma fixed got me a bit further. I also realized that while 49 is the asset object I need to access, I am not choosing a value of that object to set it to. Perhaps someone could post a solution to setting an asset object to some known value of that object. Thanks.

 

"errorMessage": "Unable to create request because of these errors : The field 'customfield_16353' is not valid for this request type '[AG-71/21; R4T] General IT Request'.",
"i18nErrorMessage": {
"i18nKey": "sd.request.create.error.failed.msg",
"parameters": [
"The field 'customfield_16353' is not valid for this request type '[AG-71/21; R4T] General IT Request'."

Suggest an answer

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

Atlassian Community Events