Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSON Body request to be sent as encodedurl postman

I have a request which need to be sent in Postman as urlencoded value like in the following (I changed some value just to be sure is not sensitive data)

notifications%3D%0A%5B%7B%22clientFileUuid%22%3A%20%22123456-fc21-496d-96d4-dfgfdgdfgfgd%22%2C%22id%22%3A%2212345678%22%2C%20%22date%22%3A%20%222023-12-04T09%3A31%3A02.678871Z%22%20%2C%22event%22%3A%22ACCEPTATION%22%2C%20%22externalId%22%3A%20%22222222222-fc21-496d-96d4-a00bd36a0be0%22%7D%5D

The same need to be prepared in its decoded form which is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

notifications=
[{"clientFileUuid": "123456-fc21-496d-96d4-dfgfdgdfgfgd","id":"12345678", "date": "2023-12-04T09:31:02.678871Z" ,"event":"ACCEPTATION", "externalId": "222222222-fc21-496d-96d4-a00bd36a0be0"}]

How can I prepare the decoded request to be sent in encoded form like above?
Is there any pre-request script we can configure to achieve the goal?

I tried with x-www-form-urlencoded variables, I tried to create a request in the pre-request but I’m not succeeding.
In general this:
notifications=[{"field" : "value"}]
it comes difficult to me to be configured.
Any idea ?

>Solution :

Use JSON.stringify() to convert to JSON, then encodeURIComponent() to URL-encode it.

const notifications = [{
  "clientFileUuid": "123456-fc21-496d-96d4-dfgfdgdfgfgd",
  "id": "12345678",
  "date": "2023-12-04T09:31:02.678871Z",
  "event": "ACCEPTATION",
  "externalId": "222222222-fc21-496d-96d4-a00bd36a0be0"
}];
let encoded = encodeURIComponent("notifications=\n" + JSON.stringify(notifications));
console.log(encoded);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading