Put method don't work when create a issue

Hello, i am tryng use the put method into my code but when i create a new issue the program call him and no return anything, and if i edit an already created issue the call work succefully.

image

if i check log the code enter into the try and print the first console log but after that no work.

Hi there,

can you please post your “updatePayload” object. Maybe you have a bug in your json body. But we can’t judge that without the object.

Regards,
Adrian

 const updatePayload = {
        method: "PUT",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
            update: {
                [customFieldId]: [
                    {
                        set: {
                            id: optionId
                        }
                    }
                ]
            }
        })
    }

I see…
In an App I’m developing myself, I also use the Update Issue API. This is how i define my request Body.

var bodyData = `{
        "fields": {
            "${fieldId}": {
                "value": "${newFieldValue}"
            }
        }
    }`;

I hope this will help you.
Regards,
Adrian

Hello @AdrianSomesan , the error is not in the JSON.
The code shared is used on creation and update event
On update event is working fine, but when is called by the creation event it doesn’t work.
The try catch doesn’t even show an error.

@MarceloMella,

That behavior is exactly as specified by the API. There’s no reason PUT should work for create:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put

For create, you’ll need to use POST:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post

1 Like

@ibuchanan , i would like to clarify that the code is triggered by the creation or update event.

The code updates the issue after the creation, so the issue already exists and doesn’t need to be created. PUT method is the right one to use on that case. The code is working fine when triggered by update event, but is not working on created event.

The thing is that the code stops execution on the api call, and doesn’t return any error, even we have a try/catch in place.

I was thinking in adding a setTimeout, but the created event is supposed to be raise after creation and after everything is done.

for complement if i use “console.log(responseUpdateIssue.status)” dont return anything :confused:

One thing i notice, is that the logs are only being registered until the API Call.
Even if it is update or create event, the logs stop before that call.
On creation event, there is no update of the issue, but on update event, there is.

It’s like @MarceloMella says, I have a trigger event for the creation/editing of an incident. When creating, it’s not applying the PUT change within the created ticket. However, if I modify the ticket, the PUT change is applied. It’s worth mentioning that in both cases creation and editing, the PUT is not returning a response of console.log("responseUpdateIssue: “, responseUpdateIssue). Similarly, if I use responseUpdateIssue.status, it doesn’t return anything.”