Hi,
I'm trying to create work items for a JIRA project. In these work items, there are two custom fields that are for JIRA asset management objects. Whenever I send a successful payload to Jira to create a work item with these custom fields filled out, the objects never appear. I am using python requests, and this is the payload that I am sending to the REST API 3 issue endpoint:
payload = json.dumps({
'fields': {
"customfield_11416": [ #Robot Shortname Field
{"key": f"{vehicle_obj.workspaceId}:{vehicle_obj.jiraAssetId}"}
# 'key': f"<our-service-workspace-id>:<an object id that exists>"
],
"customfield_11738": [ #Service Action/Labor Op field
{"key": f"{service_action.workspaceId}:{service_action.jiraAssetId}"}
# 'key': f"<our-service-workspace-id>:<an object id that exists>"
],
'issuetype': {
'name': 'Work Order'
},
"parent": {
"key": 'RLB-10706'
},
'project': {
'key':'SVC'
},
'summary': summary, #String I make earlier
}
})
The work item is created just fine, but neither object is populated in their field. I'm really trying to avoid using Jira automations since their bandwidth is a bit slow, and I'm trying to bulk create 200+ issues at a time. If there is some gotcha when trying to populate certain jira asset management object fields, that would be very helpful to know. For what it is worth, I have also tried retro-actively updating the same custom fields with a PUT payload, like the following, with the same luck.
payload2 = json.dumps({
'fields': {
"customfield_11416": [ #Robot Shortname Field
{"key": f"{vehicle_obj.workspaceId}:{vehicle_obj.jiraAssetId}"}
],
"customfield_11738": [ #Service Action/Labor Op field
{"key": f"{service_action.workspaceId}:{service_action.jiraAssetId}"}
]
}
})
Do I need to be using a different keyword than fields to update these fields?
Hi Alex. Welcome to the Atlassian community!
By your code, I assume you already, but just to make sure, to set the value of a custom fields linked to an assets schema, you'll need the workspace id. There is one per site and you can get it in this link: https://{{YOUR_ATLASSIAN_SITE}}.atlassian.net/rest/servicedeskapi/insight/workspace
To set the object, you'll need to pass the workspaceid and the id of the object using the format below:
"customfield_12922": [
{
"id": "320f82h-6925-4f0c-a25d-4968f6e10327:116"
},
{
"id": "320f828h-6925-4f0c-a25d-4968f6e10327:117"
}
]
Assuming the the workspace id is "320f82h-6925-4f0c-a25d-4968f6e10327" and the objects are "116" and "117"
Yes, I am/was mostly doing that. However, when I went to go look at the work item, neither of the fields were updated.
In your code snippet you are using 'id' instead of 'key' as the search/set option for those custom fields. This was a few days ago when I was trying this, so I can't remember if I tried something like your ex:
{"id":"320f82h-6925-4f0c-a25d-4968f6e10327:116"}
specifically, but I know that I tried the following examples (workspace id and object id are different on my end):
{"key":"320f82h-6925-4f0c-a25d-4968f6e10327:116"}
{"id":"116"}
{"name":"myObjectName"}
None of the above were working, and didn't an error when trying to create the issue FWIW.
I'll give 'id' a shot, but my workaround for now has been to send a payload to a Jira Automation and then have that automation set those fields using AQL. I'll post back here to see if changing to id: workspace:objectId works for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, yep. Replacing 'key' in my originally posted payload with 'id' did the trick (fixed below). I had some old code lying around that I though worked that was using 'key', but I guess it never worked....?
@Deivid AraujoIs there documentation that shows how these custom field payloads should be constructed? I may not have been very thorough, but I have found it hard to find any info on the Jira Rest API v3 in combination with the Jira Asset Management. I feel like I've been stumbling around in the dark a lot to get things to work.
payload = json.dumps({
'fields': {
'issuetype': {
'name': 'Work Order'
},
"customfield_11416": [ #Robot Shortname Field
{"id": f"{vehicle_obj.workspaceId}:{vehicle_obj.jiraAssetId}"}
# 'id': f"<our-service-workspace-id>:<an object id that exists>"
],
"customfield_11738": [ #Service Action/Labor Op field
{"id": f"{service_action.workspaceId}:{service_action.jiraAssetId}"}
# 'id': f"<our-service-workspace-id>:<an object id that exists>"
],
"parent": {
"key": f'{service_action.associated_ticket}'
},
'project': {
'key':'SVC'
},
'summary': f"{vehicle_obj.objectLabel}: {service_action.objectLabel}",
}
})
response = requests.request("POST", postURL, data=payload, headers=jiraHeaders, auth=jiraAuth)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex.
I'm glad changing from "key" to "id' worked.
As for the documentation, I'm afraid I had/have the same experience as you. I did find this article that shows how to update an assets custom field via the automation and just applied the same concept to the API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.