Bad Request Error when trying to update issue

Hi,

I am trying to update issue description field and constantly getting 400 Bad request error message.
My function body looks like this

const response = await api.asApp().requestJira(`/rest/api/3/issue/${id}`, {
    method: "PUT",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json",
    },
    body: JSON.stringify(payload),
  }

and payload is

{
    "update": {},
    "fields": {
        "description": {
            "version": 1,
            "type": "doc",
            "content": [
                {
                    "type": "paragraph",
                    "content": [
                        {
                            "type": "text",
                            "text": "test Description…updating…"
                        }
                    ]
                },
                {
                    "type": "paragraph",
                    "content": [
                        {
                            "type": "text",
                            "text": "Linked Stories"
                        }
                    ]
                },
                {
                    "type": "orderedList",
                    "content": [
                        {
                            "type": "listItem",
                            "content": [
                                {
                                    "type": "paragraph",
                                    "content": [
                                        {
                                            "type": "text",
                                            "text": "10024"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    }
}

I have tried tried description as part of UPDATE block as well but still get the same error

{"headers":{},"ok":false,"status":400,"statusText":"Bad Request"}

any ideas what I am missing here or doing wrong???

Thanks

Hi @jmadan, this seems to be a bug. Could you confirm that the issue actually gets updated despite taht failed request?

Accordingly to the docs Jira returns 204 status. It doesn’t return anything else besides that so when the response is processed as a JSON one, it fails because JSON.parse(undefined) fails. If this is the case, we have to fix it on the Forge side.

Hi… I can confirm that issue does not get updated :frowning:

In such case there must be something else. Do you have proper permissions set in the manifest.yml e.g. write:jira-work and read:jira-work? Also consider running forge install --upgrade, the scopes might be outdated.

I am able to create issue but not update it. I have both permissions set in my manifest.yml write:jira-work and read:jira-work

when you are getting 204 response back… can you share the payload? I am not sure if description field should be in Update block or fields block.

Interesting! I’ve used the payload you shared and the result of the request is:

{ /* .... */
  ok: true,
  status: 204,
  statusText: 'No Content'
}

Also the issue was updated as expected. Does the result change if you make that request as user (api.asUser().requestJira()) or try it with a brand new project? Perhaps that could be the case. I’ll also ask my team mates about this case as there must be some permission magic involved.

Edit: one more thing I’d like to ask you. Could you please check what is printed in the terminal after you replace your code with the one below?

const response = await api.asApp().requestJira(`/rest/api/3/issue/${id}`, {
  method: "PUT",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});

const text = await response.text();
console.log(text);

for response.text() I get the following error
{"errorMessages":["Can not instantiate value of type [simple type, class com.atlassian.jira.rest.v2.issue.IssueUpdateBean] from JSON String; no single-String constructor/factory method"]}

based on the above error…I figured the issue was that JSON.stringify of payload for request. removing that gets me 204 response and issue gets updated.

Glad to hear that!