Passing an array to an external system

Hi,

I’m sorry but I’m quite out of my depth here and I need a helping hand to pull me out of this hole.

I’m using the PHP server model and through a server action API, I’m trying to invoke an API of an external system using a POST call. This POST call passes information about an Order. It sends fields about the order itself and an array of Items, with its own fields to describe them. (The actual case is a bit different, but this is simpler to explain and solving this would solve my problem. In essence an Order has at least one Item.)

In my API call, the JSON Data field looks like this:

{
“sessionid”: “7debd793-940f-4956-a4b8-21d592c344b2”,
“outputtype”: “Json”,
“BatchHeaderFolderID”: “{{OrderHeader[0].OrderNum}}”,
“ProcessingBot”: “{{OrderHeader[0].OrderDate}}”,
“ProcessingResult”: “{{OrderHeader[0].OrderType}}”,
“ListOfOrderItems”: “{{ItemList}}”
}

Both {{OrderHeader[0].blah}} and {{ItemList}} are the result of a query to my database.
The DB query ItemList returns a set set with N records containing something like: ProductName, Quantity, and Unit Price and that query result is assigned to the array ListOfOrderItems. I think that this is where the problem resides, btw.

The external system, the one who responds to my POST call, accepts all the scalar fields (i.e., all those that are not an array, like OrderNum, OrderDate, OrderType) but cannot seem to understand the elements of the array provided by the result of the query called ItemList, even though it understands that are N items in the array I’m sending to it.

I heard that I may need to “encode” the array although I don’t think I understand
a) what encoding means
b) why it is required in the array but not on the scalar items
c) more importantly, what I need to do to solve this issue

I would really appreciate any guidance that anyone can provide me on how to do this.

Many thanks in advance!

Alex

PS: there is a question similar to mine posted already but has no answer.

Community Page
Last updated: