Convert multi line JSON into single line

Hello everyone,

I’m trying to send the following jsonPayload through a HTTP Request activity where first I use the assign activity to create this string and then I add the jsonPayload in the Body part of the HTTP Request properties.

the Request body should resemble the following:

{
  "createdAt": "2024-03-25T13:28:28.936Z",
  "serviceId": "DMSCOMPACTTRIAGE",
  "processInstanceId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "origin": "UIPATH"
}

where createdAt is supposed to be a timestamp of the exact time the bot got executed - I’m using System.DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss”) and processInstanceId is supposed to be a random UUID - I generate it like this Guid.NewGuid.ToString

my jsonPayload looks like this "{""createdAt"":""" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + """,""serviceId"":""DMSCOMPACTTRIAGE"",""processInstanceId"":""" + Guid.NewGuid.ToString + """,""origin"":""UIPATH""}" but I’m getting error 400 Bad Request as a response, so I’m wondering what I’m doing wrong?

Thanks for your help!

When ISO Date Format is needed

grafik

UPD1 -
And also:
grafik
Where appending Z is not reflecting UTC but can be achieved by
grafik

thank you for this remark, unfortunately I’m still getting the same 400 bad request when I try to preview the response from the http request wizard. But when I run the whole process the status code is 0 and the response and headers are empty.

in such cases we recommend:

I’m still getting a 400 bad request. I checked on Postman and it works as desired, I have added the same endpoint and authorization token.
image
this is my workflow

I’m unable to paste the http request config image but I have added the following in the properties:

  • Request Method - POST
  • Request URL - correct URL that I need to send the POST method to (checked on Postman and I am sure its the right one)
  • OAuth2Token - in order to reach this endpoint I need an Authorization Bearer token
  • Body - jsonPayload (created with the assign activity from the screenshot above -

“{‘createdAt’:'” + System.DateTime.UtcNow.ToString(“yyyy-MM-ddTHH:mm:ss:fffZ”) + “‘,‘serviceId’:‘DMSCOMPACTTRIAGE’,‘processInstanceId’:’” + Guid.NewGuid.ToString + “',‘origin’:‘UiPath’}”

looks like this)

  • Body Format - application/json

maybe you can show us the curl from POSTMAN

I can’t share the whole thing since there are confidential info (some parts have been edited)

curl --location 'https://proxy/api/endpoint' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJqYlh0WGdkUllpSVZ5Z0dxNF93SmZFM3J.....' \
--data '{
  "createdAt": "2024-03-28T13:47:00.111Z",
  "serviceId": "DMSCOMPACTTRIAGE",
  "processInstanceId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "origin": "UIPATH"
}'

Absolutely fine

So we cross-check against the POSTMAN
grafik

And create the payload JSON:


Kindly note: \" is visual and not part of the content

So it left:

But would check:

And maybe trying both

thank you for your help! I was escaping the double quotes incorrectly which is why I kept getting 400 Bad Request.
the solution that worked for me in the end was the following:
"{""createdAt"": """+Now.ToString("u").Replace(" ","T")+""", ""serviceId"": ""DMSCOMPACTTRIAGE"", ""processInstanceId"": """+Guid.NewGuid.ToString+""", ""origin"": ""UIPATH""}"

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.