Articles in this section

Set up JSON mapping for an HTTP(S) import from a NetSuite saved search

This example shows how to set up a JSON mapping for an HTTP(S) import that receives data from a NetSuite saved search. The API includes top-level fields for Test, ClientName, and ClientCode, and can contain multiple orders in one request.

Mapping template

{
  "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}}
    ]
  }
}

How the template works

  • Each element in data is a single order, so the template iterates orders with {{#each data}}.
  • Each order is an array of line items with repeating header information (the saved-search results). Reference a header-level field with the index 0 — for example, {{0.id}} — to read it from the first line item.
  • Wrap any field name that contains a space in square brackets, for example {{0.[Shipping Address 1]}}.
  • A nested {{#each this}} iterates the line items. These fields aren't prefixed with 0, because each iteration handles one line item at a time, for example {{Item}} and {{Quantity}}.
  • The {{#if @last}}{{else}},{{/if}} expression adds a comma after every element except the last. JSON arrays require a comma between elements, but not after the final element.