So I need to make a POST call to my Cloud Functions. I need to pass. SON with list of LineItems like to the body of the call as shown below.
{
"lineItems": [
{
"amount": 50.0,
"taxableAmount": 40.0,
"taxable": true,
"discountAmount": 5.0
},
{
"amount": 30.0,
"taxableAmount": 25.0,
"taxable": false,
"discountAmount": 2.0
}
],
"deposit": {
"documentId": "D123",
"companyId": "C456",
"type": "PERCENTAGE",
"value": 10.0
},
"discount": {
"id": "DIS789",
"companyId": "C456",
"name": "Discount 1",
"type": "AMOUNT",
"value": 5.0
},
"taxRate": 8.5,
"shippingCost": 7.0
}
If I copy the above and past into API connector, it works fine. However I need to dynamically pass in the value so I change it to
{
"lineItems": <lineitems>,
"deposit": {
"documentId": <depositId>,
"companyId": <companyId>,
"type": <depositType>,
"value": <depositValue>
},
"discount": {
"id": <discountId>,
"companyId": <companyId>,
"name": <discountName>,
"type": <discountType>,
"value": <discountValue>
},
"taxRate": <taxRate>,
"shippingCost": <shippingCost>
}
And the calls are failing because of JSON SyntaxError.
I have tried to make the array as "lineItems":[ <lineitems>],
Anyone have an example of how you pass dynamic sized array of objects to a POST body?
I don’t think the issue is formatting the JSON items, but letting the API connector know that this field is an array.