Invalid request payload on POST issue

I have tried everything possible to create a new ticket. What I really need is a subtask of the triggering issue, but for now I would settle with creating any ticket in Forge via the rest API.

INFO    06:49:34.815  4df860bf97dca2d9  Creating subtask for Greg Tucker accountId=5bf24d1759e69b35f160cccc.
INFO    06:49:34.816  4df860bf97dca2d9  bodyData: {"fields":{"project":{"id":"10112"},"issuetype":{"id":"10251"},"parent":{"key":"SPR-344"},"assignee":{"id":"5bf24d1759e69b35f160cccc"},"description":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"UI testing is different from unit testing, UI testing is focusing on the interaction between user and UI. abcdefghijklmnopqrstuvwxyzabcdefg"}]}]},"summary":"UI Testing","labels":["Android"],"reporter":{"id":"5bf24d1759e69b35f160cccc"}}}
INFO    06:49:35.922  4df860bf97dca2d9  Response: 400 Bad Request
INFO    06:49:35.925  4df860bf97dca2d9  {
  errorMessages: [
    'Invalid request payload. Refer to the REST API documentation and try again.'
  ]
}

Here is my json payload:

{"fields":{"project":{"id":"10112"},"issuetype":{"id":"10251"},"parent":{"key":"SPR-344"},"assignee":{"id":"5bf24d1759e69b35f160cccc"},"description":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"UI testing is different from unit testing, UI testing is focusing on the interaction between user and UI. abcdefghijklmnopqrstuvwxyzabcdefg"}]}]},"summary":"UI Testing","labels":["Android"],"reporter":{"id":"5bf24d1759e69b35f160cccc"}}}

Any idea what field I am missing? I have tried adding and removing fields, but just cannot get anything to work. I wish the error message was a little more specific about what’s wrong.

Hello @GregTucker

You haven’t said which version of the REST API you’re using, or which endpoint, but since you’ve declared the description field in ADF, can we assume that you’re using the v3 Create Issue endpoint?

What happened when you stripped the request back to the bare minimum and provided only the project, issuetype, parent and summary fields?

1 Like

Thanks for the reply. You are correct, I am using v3. Here is my code:

      var bodyData = {"fields": subtaskFields, "update": {}};
      console.log("bodyData: %s", JSON.stringify(bodyData))
      const response = await api.asApp().requestJira(route`/rest/api/3/issue`, {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: bodyData
      });
      console.log(`Response: ${response.status} ${response.statusText}`);
      console.log(await response.json()); 

But no, it still doesn’t work with the minimal fields.

INFO    00:53:01.991  e93e357b921f86c4  bodyData: {"fields":{"project":{"id":"10112"},"issuetype":{"id":"10251"},"parent":{"key":"SPR-344"},"summary":"UI Testing"},"update":{}}
INFO    00:53:03.064  e93e357b921f86c4  Response: 400 Bad Request
INFO    00:53:03.067  e93e357b921f86c4  {
  errorMessages: [
    'Invalid request payload. Refer to the REST API documentation and try again.'
  ]
}

The JSON in the body of the request looks valid, so there is something else causing a problem, mostly likely in your coding.

I don’t do much Forge work, but I thought you had to JSON.stringify the bodyData object before using it:

const response = await api.asApp().requestJira(route`/rest/api/3/issue`, {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(bodyData)  <-- STRINGIFY THE OBJECT HERE
      });
  1. Have you tried submitting the same request body via an API test tool like Postman to isolate the code from the request?
  2. Is this the only request type or endpoint failing, or are all requests to all endpoints failing? IE, can you create a plain Story or Epic without problem?
  3. What happens if you change some of the parameters types? IE, instead of referring to the project by id, use its key. Instead of the issuetype by id, use its actual name (IE “Story”, if that is the parent issue type).

Try breaking the problem down into smaller pieces to find the specific thing that is failing

You caught the issue right away: I needed to stringify the JSON object.

I spend more time with a strongly typed language (go) that catches these issues in VSCode and at compile time. I didn’t realize the json variable created in the online help was actually a string, not a JSON object.

Thanks so much for your feedback.

No problems.

Wow, someone who uses Go. Now I don’t feel so bad about once using SmallTalk :wink:

Lots of people use go, but few will admit it. :wink: