How to create a Customer Request via API with Forms and Assets object fields

Still need help?

The Atlassian Community is here for you.

Ask the community

 

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

 

Summary

In Jira Service Management Cloud, starting from January 2023, it is now possible to utilize the custom fields of Assets objects in Forms. Subsequently, in October 2023, the Forms API was introduced.

These two developments enable the submission of requests via API with Forms data containing Assets Objects fields.


Getting Forms IDs

On our API documentation, there is an example of how to create a request with Forms linked to a Request type:

In order to get the options and types to add Forms on the API you need to:

cURL (terminal) example:
curl --request GET \
  --url 'https://api.atlassian.com/jira/forms/cloud/<cloudid>/project/<pkey>/form' \
  --user '<email>:<token>' \
  --header 'X-ExperimentalApi: opt-in' \
  --header 'Accept: application/json'

Alternatively, via Automation's Send Web Request Action:

Automation Example:
Web request URL* (required):
  https://api.atlassian.com/jira/forms/cloud/<cloudid>/project/{{project.key}}/form
HTTP method* (required):
  GET
Web request body* (required):
  Empty
Delay execution of subsequent rule actions until we've received a response for this web request:
  Checked
Continue running the rule even if the request response is not successful (i.e. non-200 response):
  Unchecked
Headers (optional):
  content-type: application/json
  X-ExperimentalApi: opt-in
  Authorization: Basic {{base64Encode('<email>:<token>')}}



cURL (terminal) example:
curl --request GET \
  --url 'https://api.atlassian.com/jira/forms/cloud/<cloudid>/project/<pkey>/form/<form id>' \
  --user '<email>:<token>' \
  --header 'X-ExperimentalApi: opt-in' \
  --header 'Accept: application/json'

Alternatively, via Automation's Send Web Request Action:

Automation Example:
Web request URL* (required):
  https://api.atlassian.com/jira/forms/cloud/<cloudid>/project/{{project.key}}/form/<form id>
HTTP method* (required):
  GET
Web request body* (required):
  Empty
Delay execution of subsequent rule actions until we've received a response for this web request:
  Checked
Continue running the rule even if the request response is not successful (i.e. non-200 response):
  Unchecked
Headers (optional):
  content-type: application/json
  X-ExperimentalApi: opt-in
  Authorization: Basic {{base64Encode('<email>:<token>')}}

As we can see from the results, the Assets objects field only shows the custom field ID and name. If we follow the steps using the example on the API documentation we would just add the “choices” and a number, but for Assets this is different as it will require a combination of the Workspace ID + the Object ID.


Getting Assets information

Workspace ID

The Workspace ID can be retrieved via API or by exporting an issue that already has an Assets field.

Via API, you just need to change the <site> to your instance domain and paste it to your browser:

https://<site>.atlassian.net/rest/servicedeskapi/assets/workspace

Object ID

This value is easier to get as it’s the number on the Object Key.

Once you have these two details, it’s possible to raise the request with the Forms + Assets fields.


cURL (terminal) example:
curl --request POST \
  --url 'https://<site>.atlassian.net/rest/servicedeskapi/request' \
  --user '<email>:<token>' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
  "form": {
    "answers": {
      "1": {
        "text": "Answer to a text form field"
      },
      "4": {
        "choices": [
          "123ed45a-6f7d-8c9c-bc10-c123b4567891:55"
        ]
      }
  },
  "requestFieldValues": {
    "description": "I need a new *mouse* for my Mac",
    "summary": "Request JSD help via REST"
  },
  "requestTypeId": "25",
  "serviceDeskId": "10"
}'

In the above example, we have 123ed45a-6f7d-8c9c-bc10-c123b4567891 which is the Workspace ID, and 55 which is the Object ID. From the screenshot, it refers to the IT-55 object.

This said, when raising requests via API with Forms that contain Assets fields, the format will be “workspaceid:objectid” - "123ed45a-6f7d-8c9c-bc10-c123b4567891:55".

Alternatively, via Automation's Send Web Request Action:

Automation Example:
Web request URL* (required):
  https://<site>.atlassian.net/rest/servicedeskapi/request
HTTP method* (required):
  POST
Web request body* (required):
  Custom Data:
    {
    	"form": {
			"answers": {
				"1": {
					"text": "Answer to a text form field"
				},
				"4": {
					"choices": [
						"123ed45a-6f7d-8c9c-bc10-c123b4567891:55"
					]
				}
		},
		"requestFieldValues": {
			"description": "I need a new *mouse* for my Mac",
			"summary": "Request JSD help via REST"
		},
		"requestTypeId": "25",
		"serviceDeskId": "10"
	}
Delay execution of subsequent rule actions until we've received a response for this web request:
  Checked
Continue running the rule even if the request response is not successful (i.e. non-200 response):
  Unchecked
Headers (optional):
  content-type: application/json
  X-ExperimentalApi: opt-in
  Authorization: Basic {{base64Encode('<email>:<token>')}}

Further Reading

Last modified on Jun 25, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.