Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sending API web request error with multiple lines

steven.allcock
Contributor
November 5, 2024

HI,

 

I am trying to send an web request API to a status page we have and when there is a single line of text in the custom field it works however if you add any new lines the request fails with BAD REQUEST

e.g - working

No business impact. No customer impact 

e.g - Not Working

No Business impact

No Customer Impact

What do i need to change to the "incident_details" part to make multiple lines work in the API web request!? (it's also the same with Business /Customer impact but the fix for this will apply here)

Here is my API Call

{ "statuspage_id": "XYZ",

"incident_id": "{{issue.customfield_14416}}",

"incident_details": "\n Incident Update: {{issue.customfield_14408}} \n \n Business/Customer Impact: {{issue.customfield_14409}} \n \n Next Update: We will provide a further update in {{issue.customfield_14414}}.\n \n Incident Manager: {{issue.customfield_13934}} \n \n Impact Start time: {{issue.Customfield_14410.mediumDateTime}}",

"message_subject": "Incident Update: {{issue.summary}}",

"notify_email": "1",

"notify_sms": "0",

"notify_webhook": "0",

"social": "0", "irc": "0",

"msteams": "0",

"slack": "0",

"current_status": {{currentstatusvalue}},

"current_state": {{currentstatevalue}}

}

1 answer

0 votes
Tuncay Senturk
Community Champion
November 5, 2024

Hi @steven.allcock 

the newline characters (\n) in your custom field are causing the JSON to become invalid. You can use .escaprJson function to escape special characters like new line in you case

{{issue.customfield_14408.escapeJson}}

if it does not work you might want to escape characters by replacing them

"incident_details": "{{issue.customfield_14408.replace("\n", "\\\\n")}}", 

 

steven.allcock
Contributor
November 5, 2024

Hi @Tuncay Senturk 

Ive updated it like this and now the value is empty, any ideas?

"incident_details": "\n Incident Update: {{issue.customfield_14408.escapeJson}} \n \n Business/Customer Impact: {{issue.customfield_14409}} \n \n Next Update: We will provide a further update in {{issue.customfield_14414}}.\n \n Incident Manager: {{issue.customfield_13934}} \n \n Impact Start time: {{issue.Customfield_14410.mediumDateTime}}",

Tuncay Senturk
Community Champion
November 5, 2024
Oh, sorry! I was almost sure I had used it before, but I might be wrong.

Could you try replacing \n characters as below?

"incident_details": "{{issue.customfield_14408.replace("\n", "\\\\n")}}", 

 

steven.allcock
Contributor
November 5, 2024

No im still getting request, have i got this right?

"incident_details": "\n Incident Update: {{issue.customfield_14408.replace("\n", "\\\\n")}} Business/Customer Impact: {{issue.customfield_14409}} \n \n Next Update: We will provide a further update in {{issue.customfield_14414}}.\n \n Incident Manager: {{issue.customfield_13934}} \n \n Impact Start time: {{issue.Customfield_14410.mediumDateTime}}",

Tuncay Senturk
Community Champion
November 5, 2024

Hmm, let's try one more thing

"incident_details": "{{issue.customfield_14408.replace('\n', '\\\\n')}}", 

or this

"incident_details": "{{issue.customfield_14408.replace('\n', '\\n')}}", 

I apologize; I should have recreated the content and written it accordingly.

steven.allcock
Contributor
November 6, 2024

Hi I tried this but i got an error in the audit log

it was unable to pull a value from the customfield

Do you have anymore suggestions?

Tuncay Senturk
Community Champion
November 6, 2024

I could not understand how it was unable to pull a value from the customfield? 

steven.allcock
Contributor
November 6, 2024

image (120).png

steven.allcock
Contributor
November 6, 2024

{
"statuspage_id": "xyz",
"incident_id": "{{issue.customfield_14416}}",
"incident_details": "{{issue.customfield_14408.replace('\n', '\\n')}}",
"message_subject": "Incident Update: {{issue.summary}}",
"notify_email": "1",
"notify_sms": "0",
"notify_webhook": "0",
"social": "0",
"irc": "0",
"msteams": "0",
"slack": "0",
"current_status": {{currentstatusvalue}},
"current_state": {{currentstatevalue}}
}

Tuncay Senturk
Community Champion
November 6, 2024

Are you certain that the custom field contains values for the issues? If it is empty or null, we may encounter an error, so it’s advisable to check if it has a value first.

 

{{#if(issue.customfield_14408)}}{{issue.customfield_14408.replace("\n", "\\n")}}{{/}}

 

steven.allcock
Contributor
November 7, 2024

The field has 2 lines of text in it so is not empty

Tuncay Senturk
Community Champion
November 7, 2024

I quickly set up an Automation rule testing both escapeJson and replace functions. Both work well, I'd suggest escapeJson as it creates json friendly string for your web requests which may cause problems (e.g. escape " character which has a meaning in Json)

However, I could not understand what is the issue in your case. I'd suggest tracing the web request and its payload, if we see what payload it produces, it will be easier to fix the problem. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events