How to Create Customer Request with Form using REST API?

Aaron Champion
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 26, 2024

Many of our Jira Service Desk Project's request types use dedicated forms to show or hide fields based on previous selections on the form. I need to be able to create customer requests through the REST API.

I used to be able to do this by ignoring the form and including the necessary fields under 'requestFieldValues', but something changed in the past several months that prevents me from doing this anymore (I think that fields can no longer be included in the request type if they exist in the attached form).

I can see POST Create Customer Request in the documentation, which should allow me to provide form fields but its unclear based on the documentation what is required for the field IDs, are these in the format of 'customfield_12345' or just '12345', or does each form have have an arbitrary number assigned to each field (how would I get this)? It's also unclear if I can provide the choice IDs, or if it prefers the text value of the selection. Choices are required as a array, what if the field only allows a single choice, is it OK to supply an array with a single value for those field types?

I have tried a variety of different variations, but I always get the same response: 'This request is invalid. Check that the request contains all the required parameters and that the parameters are valid.'

Example payload I am trying:
sample.jpg

1 answer

0 votes
Fanny Vachet
Contributor
November 7, 2024

Hi @Aaron Champion ,

We have the same requirement, did you find a solution?

Thanks

Fanny

Aaron Champion
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 8, 2024

@Fanny Vachet 

We did manage to figure this out though not without some difficulty. There may be a more efficient way to get the form questions/answers, but I'll outline below how we worked through the problem.

I don't think I found a dedicated API call to get a form's questions directly, but it is possible to reverse engineer the questions from a manually filled and submitted form.

  1. First manually submit a Customer Request with form or find one that a user has already submitted. You will need the issueKey for that request.
  2. Do a GET request to 'https://{yourOrgValue}.atlassian.net/rest/api/2/issue/{issueKey}/properties/proforma.forms.i1' (We use Jira Cloud in this example). You can do a request up one level at properties to list other forms if you have multiple forms linked, but default is i1 if you only have one form.
  3. From the returned json, look in value.design.questions and use those field ids to calculate the field ids for submitting your new form answers through API. the properties on each question Id should contain helpful details for identifying what field they are for.
  4. Translate the question ids into answer ids in a post request like below:

 

POST  https://{yourOrgValue}.atlassian.net/rest/servicedeskapi/request

{
  "serviceDeskId": "123",
  "requestTypeId": "456",
  "raiseOnBehalfOf": "ATLASSIAN_USER_ID",
  "isAdfRequest": false,
  "requestFieldValues": {
    "customfield_12345": "TEXTVALUE"
  },
  "form": {
    "answers": {
      "8": {
        "text": "TEXTVALUE"
      },
      "7": {
        "choices": [
          "81992"
        ]
      },
      "14": {
        "text": "TEXTVALUE"
      },
      "30": {
        "users": [
          "ATLASSIAN_USER_ID"
        ]
      }
    }
  }
}


Hope this helps. It's a bit of a mess to translate everything manually, but in the end it worked for us.

Fanny Vachet
Contributor
November 13, 2024

Thanks heaps !

Suggest an answer

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

Atlassian Community Events