Error 1 - Unable to parse body to JSON

Vamshi_ch123
Tera Contributor

Hi All,

 

getting an error message while updating the ticket "Unable to parse body to JSON". I have created a custom action to update the ticket in client application whenever short description , description and state is changed using flow designer

 

Vamshi_ch123_0-1690875948432.png

Vamshi_ch123_1-1690876126523.png

script : 

var jsonPayload = {
"type":"UPDATE",
"data": JSON.parse(inputs['payload'])
}
outputs['request_body'] = JSON.stringify(jsonPayload);
gs.info("The output is:"+outputs['request_body']);

})(inputs, outputs);

 

I was getting the below error message while updating the ticket

Method failed: (/XXXXXXXXXXX/dev/tickets/CS00) with code: 400

{"Response":"Unable to parse body to JSON","ReceivedBody":"{\"type\":\"UPDATE\",\"data\":{\"clientTicketNumber\":\"CS0000198\",\"description\\n\":\"Testing for Changed fields updation\",\"status\\n\":\"Assess\",\"clientName\":\"srn\",\"short_description\\n\":\"Changed fields updation\",\"ticketType\":\"Change\"}}"}
1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Try below script:

var jsonPayload = {
"type":"UPDATE",
"data": JSON.parse(inputs['payload'])
}
outputs['request_body'] = jsonPayload;  // no need to stringify it
gs.info("The output is:"+outputs['request_body']);

})(inputs, outputs);
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

3 REPLIES 3

Anil Lande
Kilo Patron

Hi,

Try below script:

var jsonPayload = {
"type":"UPDATE",
"data": JSON.parse(inputs['payload'])
}
outputs['request_body'] = jsonPayload;  // no need to stringify it
gs.info("The output is:"+outputs['request_body']);

})(inputs, outputs);
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi @Anil Lande  Thank you this was working but now the below error is getting when we try testing this.

 

Vamshi_ch123_0-1690885938444.png

 

 

 "Response""APIKey not authorized for ticket company"

Hi,

Check with third part team for the same. Looks like you have some API key that should match with another system.

It has nothing to do with your JSON Payload.

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande