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

Pavankumar_1
Mega Patron

Hi,

ServiceNow will not allow update with the invalid JSON format.

Please valid the JSON or try to add worknotes as a end user if that trigger the integration.

https://jsonlint.com/   

 

Hope you it helps you.

Please Mark ✅ Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Mahendra RC
Mega Sage

Hello Esther,

Could you pleas check once by putting the JSON key and value in " (double quotes) instead of ' (single quotes) 

Original data:

{
	'work_notes': 'PRB #: PRB0041790 I am adding some change like dev would. Here are some changes. More changes...'
}

Change it to:

{
	"work_notes": "PRB #: PRB0041790 I am adding some change like dev would. Here are some changes. More changes..."
}

{'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>"'}

The above JSON is incorrect as we have ' (single quotes) before "09-02-2022 12:34:58 and then we have ' (single quote) after We (like We've) so your key value will be like below:

'"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>"'}

Please change the Json in below format 

{"key": "value"} (key and vaule inside " double quotes) as shown below

{"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>"}

Please check once if it makes any difference.

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

hyder Gani
Tera Contributor

Use
var m =   new JSON().encode(<user value>+'');

m = m.substring(1,m.lenght-1);

Ravi Gaurav
Giga Sage
Giga Sage

 

To troubleshoot the issue you're facing with the ServiceNow API call from Jira, here are some steps and considerations:

 

1. Check the Endpoint and Method:

  • Ensure you're using the correct ServiceNow REST API endpoint for adding work notes. It should typically be something like:
    POST https://<instance>.service-now.com/api/now/table/incident/<sys_id>
    Where <sys_id> is the unique identifier of the ServiceNow ticket.

2. Payload Structure:

  • The payload you're sending should be structured properly. For adding a work note, the JSON payload typically looks like this:
    { "work_notes": "Your work note text here" }
    Ensure that the key work_notes is correctly named and that the text you want to include is a valid string.

3. Field Length and Content:

  • Verify that the text from the Jira ticket body doesn't exceed any character limits set by ServiceNow for the work_notes field. Long text or special characters may cause issues.

4. Authentication:

  • Ensure that the credentials or authentication token used in the API call have the necessary permissions to add work notes to the ticket.

5. Error Messages:

  • If possible, share the specific error message you're receiving from ServiceNow. The error message often gives clues about what might be wrong (e.g., missing fields, permissions issues, etc.).

6. Escaping Special Characters:

  • If the Jira description contains special characters (e.g., quotes, backslashes), ensure that they are properly escaped in the JSON payload.

7. Testing with Postman or Curl:

  • Test the API call outside of Jira (e.g., using Postman or Curl) with a sample payload to see if it works. This helps isolate whether the issue is with Jira or the ServiceNow API.

Example of a Curl Command:

 

curl -X POST \ https://<instance>.service-now.com/api/now/table/incident/<sys_id> \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -u 'username:password' \ -d '{ "work_notes": "This is a sample work note." }'

 

If you follow these steps and adjust your payload accordingly, you should be able to pin

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/