Hi,
I dont think that you can pass a json like that to a codeunit webservice. The error that you are getting is of the parameter name in the API function which is
JsonObjectText and in the API body the first parameter is
Customer.
You either need to create one text string in the API body as mentioned
here or convert your whole json body to a base64 text and pass it.
I personally prefer to do it using Base64. For-example, I have this JSON and want to pass it to a codeunit API. What I do is convert it to a base64 and then send the post request.
{
"orderDate": "2024-10-10",
"postingDate": "2024-10-10",
"customerId": "d46301ed-970b-ee11-962f-00224859f0ad",
"currencyCode": "SGD",
"salesperson": "LEROY",
"salesOrderLines": [
{
"itemId": "eb230e11-160c-ee11-962f-00224859f0ad",
"lineType": "Item",
"lineObjectNumber": "10810900019",
"description": "AXE BODY WASH (INDIA) 250ML X 12 AFRICA",
"unitOfMeasureId": "add2b303-200c-ee11-962f-00224859f0ad",
"unitOfMeasureCode": "CTN",
"quantity": 1,
"unitPrice": 17,
"locationId": "4af3149a-6a0c-ee11-962f-00224859f0ad"
}
]
}
On business central side
procedure ProcessRequest(payload: Text): Text
var
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
Base64Convert: Codeunit "Base64 Convert";
JObject, JOrder, JObjectLine : JsonObject;
JArray: JsonArray;
JToken, JTokenValue, JTokenLines : JsonToken;
JValue: JsonValue;
begin
if JObject.ReadFrom(Base64Convert.FromBase64(payload)) then begin
if JObject.Get('request', JToken) then
if JToken.IsObject then begin
JOrder := JToken.AsObject();
if JOrder.Get('orderDate', JTokenValue) then
SalesHeader."Order Date" := JTokenValue.AsValue().AsDate();
JOrder.Get('salesOrderLines', JTokenLines);
JArray := JTokenLines.AsArray();
foreach JTokenLines in JArray do begin
JObjectLine := JTokenLines.AsObject();
if JObjectLine.Get('lineType', JTokenValue) then
SalesLine.Type := Enum::"Sales Line Type"::Item;
end;
end;
end;
end;
Note that my function parameter has same name as of my json body.