Skip to main content

Set JSON body

Sets the body in JSON format from a suitable collection or string

Function SetJsonBody(Val Data) Export

ParameterCLI optionTypeRequiredDescription
Data-ArbitraryString or collection to convert to JSON

Returns: DataProcessorObject.OPI_HTTPClient - This processor object


caution

NOCLI: this method is not available in CLI version


1C:Enterprise/OneScript code example
    URL = "https://httpbin.org";
URL = URL + "/post";

RandomArray = New Array;
RandomArray.Add("A");
RandomArray.Add("B");
RandomArray.Add("C");

Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);

Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetJsonBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
Result
{
"args": {},
"data": "{\r\n \"Field1\": 10,\r\n \"Field2\": \"Text\",\r\n \"Field3\": [\r\n \"A\",\r\n \"B\",\r\n \"C\"\r\n ]\r\n}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Charset": "utf-8",
"Accept-Encoding": "gzip",
"Content-Length": "81",
"Content-Type": "application/json; charset=utf-8",
"Host": "httpbin.org",
"User-Agent": "1Script v$2.0.0.0",
"X-Amzn-Trace-Id": "Root=1-68c8ad70-0137594e47255bc872980441"
},
"json": {
"Field1": 10,
"Field2": "Text",
"Field3": [
"A",
"B",
"C"
]
},
"origin": "***",
"url": "https://httpbin.org/post"
}