0

I am making this call to make comments to service now:

url = 'https://myinstance.service- 
now.com/api/now/table/incident/' +  sys_id

user = 'user'
pwd = 'pass'

headers = {"Content- 
Type":"application/json","Accept":"application/json"}

# Do the HTTP request
response = requests.patch(url, auth=(user, pwd), headers=headers ,data="{\"work_notes\":\"" +  comment + "\"}")

if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    print(comment)

And this works when the comment variable is just one line, but with multiple lines it breaks, I removed the \n from string and it does work. So how do I process this request with multiple lines, I cant get rid of the spaces the comments have to look well formatted. The comment is coming from zendesk api.

The print statement after the if not status 200 prints as following with multiple lines:

this
is
a
test
  • How are you removing the line breaks? Did you try removing \n and \r and leaving spaces? - https://stackoverflow.com/a/16566351/2223138 – Jimmy Long Sep 05 '18 at 16:17

1 Answers1

0

It was pretty simple, had to turn that part of the request into a JSON like this:

data = {}
data['work_notes'] = comment
comment = json.dumps(data)