API call returning "not valid json" error

Esther Strom
Kilo Explorer

Please bear with me; I am a Jira admin and don't know much about ServiceNow. I've been asked to use Jira's automation rules to make a SNOW API call to add a work note to a SNOW ticket that's linked to a Jira ticket when the Jira ticket's Description field (the body of the ticket) is updated.

I do have other integrations that work correctly (i.e. adding a work note when the linked Jira ticket is marked as Closed). But the request for this one was to include the text from the ticket body in the work note.

This is what my api call configuration looks like:

find_real_file.png

Here's the error I'm getting back from SNOW:

find_real_file.png

Here's the actual payload being sent; the contents are 100% valid json.

find_real_file.png

Does anyone have any ideas what ServiceNow doesn't like about this?

 

8 REPLIES 8

Tony Chatfield1
Kilo Patron

Hi, testing this quickly (based on screenshots) with Postman, I do not receive an error using table API and PUT to update an incident in a PDI and this is an accepted format

{'work_notes':'PRB #: some test………………..'}
but this returns JSON format error
{'work_notes':'PRB #: PRB12345678 some test………………..
a new line'}
 
So If you payload includes a new line you may need to ensure you are using compatible char, maybe try this.
{'work_notes':'PRB #: PRB12345678 some test………………..\na new line'}
 
Otherwise, if you could share you message and payload as plain text it would be easier to assess.

Esther Strom
Kilo Explorer

Thank you for the response, and sorry for the delay - I've been out of office.

I don't have control over the text that's being sent; it's pulling info in from the Comments field on whatever Jira ticket triggered the automation. Here's an example of the exact payload that also caused the same error:

{'work_notes':'"09-02-2022 12:34:58 - Guest (Additional comments)\nreply from: WP@x.com\n\nHey Roger,\n\nWe've escalated this to web maintenance for further review.\n\nJohn Doe\nSystems Specialist | Web Portal Applications Team\nService Desk\njohn.doe@x.com<john.doe@x.com>"'}

And the response payload:

{
  "error": {
    "message": "Exception while reading request",
    "detail": "The payload is not valid JSON."
  },
  "status": "failure"
}



Hi, using a couple of online JSON validators to check your message, I get an invalid result.

https://jsonlint.com/
https://www.jsonschemavalidator.net/

I recommend that the next step would be to engage whoever is responsible for the JSON payload and have it reviewed\corrected.

 

 

JSON mandates double quotes as property name and value delimiters. So those strings are not valid JSON. So no wonder you get errors.