Below is an example of how to set up a JSON mapping for a HTTP(S) import that is coming from a NetSuite saved search.
This API uses some info at the top for Test, ClientName, and ClientCode. It can also include multiple orders in one request.
Each element in data will be a single order hence the {{#each data}}
. This data element is then an array of line items with repeating header info (this is the results of the saved search). So for header level info it should use {{0.<Field Name>}}
, as you can see in the template. Any field name with a space is wrapped in []
. Then there is another {{#each this}}
to iterate through the line items. Those will not be prefixed by the 0 since it handles each element at a time.
A {{#if @last}}{{else}},{{/if}}
statement was also added so that as long as it isn't the last element of the array, it will add a comma. This is because JSON arrays must be separated with a comma, but it can't be there as the last element.
{ "UnitycartOrderPost": { "ClientName": "test", "ClientCode": "testcc", "Test": "y", "Order": [ {{#each data}} { "Subtotal": "0.00", "Total": "0.00", "ExternalID": "{{0.id}}", "AdCode": "iPost", "ShipFirstname": "Test", "ShipLastname": "Fufillment", "ShipAddress1": "{{0.[Shipping Address 1]}}", "ShipCity": "{{0.[Shipping City]}}", "ShipState": "{{0.[Shipping State/Province]}}", "ShipZip": "{{0.[Shipping Zip]}}", "ShipPhone": "", "Email": "{{0.[Customer Email]}}", "UseAsBilling": "y", "PaymentType": "5", "Items": { "Item": [ {{#each this}} { "Inv": "{{Item}}", "Qty": "{{Quantity}}", "PricePer": "{{Amount}}", "NumOfPayments": "1" } {{#if @last}}{{else}},{{/if}} {{/each}} ] } } {{#if @last}}{{else}},{{/if}} {{/each}} ] } }
Sample Mapping
Sample Data
Comments
Please sign in to leave a comment.