Build a String from Json file

Hello,

I had the following Json code:

	{
			"name": "Créer dossier name",
			"event": [
				{
					"listen": "test",
					"script": {
						"exec": [
							"pm.test(\"Status code is 201\", function () {\r",
							"    pm.response.to.have.status(201);\r",
							"});\r",
							"\r",
							"pm.test(\"Response numen\", function () {\r",
							"    var jsonDataResponse = pm.response.json()\r",
							"    var jsonDataRequest = JSON.parse(pm.request.body.raw)\r",
							"    \r",
							"    pm.expect(jsonDataResponse.numenDossierAgent).is.not.null;\r",
							"    pm.expect(jsonDataResponse.numenDossierAgent).is.equal(jsonDataRequest.numenDossierAgent)\r",
							"});\r",
							"\r",
							"pm.test(\"Response uid\", function () {\r",
							"    var jsonDataResponse = pm.response.json()\r",
							"    pm.expect(jsonDataResponse.uid).is.not.null;\r",
							"});"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "POST",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "{\r\n    \"numen\": \"00A0009140MCA\"\r\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "http://xxxxx/ged/agents",
					"protocol": "http",
					"host": [
						"host",
						"omogen",
						"in",
						"cloe",
						"education",
						"gouv",
						"fr"
					],
					"path": [
						"ged-ruda",
						"agents"
					]
				}
			},
			"response": []
		},

and i would to pass it as a body of a Http request.

Thre is a king of formatting used in post:
https://forum.uipath.com/t/http-post-request-error/32881/27?u=abdel

but tyed with the file attached always error
creation dossier agent.txt (915 Bytes)
Jsonbody.txt (817 Bytes)

my last test gives :slight_smile:

{
  "message": "Create_response ={\"entity-type\":\"exception\",\"status\":500,\"message\":\"Internal Server Error\"}",
  "level": "Trace",
  "logType": "User",
  "timeStamp": "17:40:06",
  "processVersion": "1.0.0",
  "jobId": "8c628566-cb7a-443a-ae39-972039dae20d",
  "robotName": "abffffff@gmail.com-attended",
  "machineId": 1877763,
  "organizationUnitId": 3515672
}

Hi @Rahul_S,

I have the following Json:

{
“name”: “Créer documents”,
“request”: {
“method”: “POST”,
“header”: [
{
“key”: “xxxx-Transaction-Timeout”,
“value”: “300”,
“type”: “text”,
“disabled”: true
}
],
“body”: {
“mode”: “formdata”,
“formdata”: [
{
“key”: “fichier”,
“description”: “rib”,
“type”: “file”,
“src”: “/C:/Users/name/OneDrive - aaa PACA/General/GED-zzzz/xxxx (back-end GED)/Services exposés/documents_qualif/document.pdf”
},
{
“key”: “metadonnees”,
“value”: “{\n "numen": "00A0009140MCA",\n "nature": "conges_et_absences/conge_de_maladie_ordinaire",\n "format": "numerique"\n}”,
“description”: “json”,
“type”: “text”
}
]
},
“url”: {
“raw”: “http://apim-suite_url.fr/ged-zzzz/documents/document”,
“protocol”: “http”,
“host”: [
“apim-suite_url”,
“NomAPI”,
“in”,
“cloe”,
“education”,
“gouv”,
“fr”
],
“path”: [
“ged-zzzz”,
“documents”,
“document”
]
}
},
“response”:
}

I’m trying the following formatted on:

“{”“name”“:”“Créer document”“,”“request”“:{”“method”“:”“POST”“,”“header”“:”“[”“{”“key”“:”“xxxx-Transaction-Timeout”“,”“value”“:”“300"”,““type””:““text””,““disabled””:““true””}“”]“”,““body””:{““mode””:““formdata””,““formdata””:“”[“”{““key””:““fichier””,““description””:““rib””,““type””:““file””},{““key””:““metadonnees””,““value””:{““numen””:““00A0009140MCA””,““nature””:““conges_et_absences/conge_de_maladie_ordinaire””,““format””:““numerique””},““description””:““json””,““type””:““text””}“”]“”},““url””:{““raw””:““http://apim-suite_url.fr/ged-zzzz/documents/document””,““protocol””:““http””,““host””:“”[“”““apim-suite_url””,““NomAPI””,““in””,““cloe””,““education””,““gouv””,““fr””“]”“,”“path”“:”“[”“”“ged-zzzz”“,”“documents”“,”“arretes”“”“]”“}},”“response”“:”“”“}”

Got the following error:

{"erreurs":[{"detail":null,"id":"numen_vide","libelle":"Le champ NUMEN est obligatoire."},{"detail":null,"id":"nature_vide","libelle":"Le champ nature est obligatoire."},{"detail":null,"id":"format_vide","libelle":"Le champ format est obligatoire."},{"detail":null,"id":"fichier_manquant","libelle":"Un fichier doit être attaché au document."}]}"

despite i had put a pdf as attachement parameter the formatte JSON not work fine,

Hello Abdel,
The fastest way to build JSON is using VB.NET check this movie:
How to create JSON in VB.NET very fast (UiPath) - YouTube
You have all the code from the movie here:
startUiPathFromSalesforce/CreateJSON.txt at master · cristinegulescu/startUiPathFromSalesforce · GitHub
Thanks,
Cristian