Upsert API - LiquidAnalytics/ld-api-examples GitHub Wiki

POST /ls/api/items/upsert

Post format:

  • OAuth2 authorization header, (Authorization bearer token) and
  • Body is JSON list of LD items. "action" header denotes Create, Merge, Update, or Delete. For deletes, only the primary key fields are required in the data part of the item.

For example, Account items :

[
    {
        "headers": {
            "category": "entity",
            "type": "Account",
            "action":"Create"
        },
        "data": {
            "accountClass": "/Account/accountClass[invoiced]",
            "accountFamily": "/Account/accountFamily[]/group[]",
            "accountId": "ABC123",
            "accountNumber": "ABC123",
            "accountType": "",
            "chain": "",
            "channel": "20",
            "currency": "USD",
            "distributionPoint": "",
            "name": "EXAMPLE CUSTOMER #1",
            "orgPath": "",
            "paymentTerms": "CCOD",
            "riskCategory": "",
            "salesOffice": "",
            "storeId": "",
            "userId": "",
            "exposure": 0.0,
            "limit": 0.0,
            "creditBlock": true,
            "overallBlock": false,
            "accountLicenseInformation": [
                {
                    "licenseNumber": "TEST SAMPLES",
                    "licenseValidFrom": "2014-02-01T05:00:00+0000",
                    "licenseValidTo": "2015-02-28T05:00:00+0000",
                    "licenseType": "7"
                }
            ],
            "addresses": [
                {
                    "name": "EXAMPLE CUSTOMER #1",
                    "city": "STORYBROOK",
                    "postalCode": "12345",
                    "region": "ME",
                    "addressLine1": "1 FAIRY TALE BLVD",
                    "country": "US",
                    "addressType": "Work",
                    "addressLine2": "",
                    "addressLine3": "",
                    "addressNote": "",
                    "primary": true
                }
            ],
            "deliveryDays": [
                "Thu"
            ],
            "phones": [
                {
                    "phoneNumber": "2223334455",
                    "phoneCountryCode": "1",
                    "phoneType": "office"
                }
            ]
        }
    }
]

Post response is JSON containing count of items processed and a list of rejected items if any. For example:

{
    "count":2
}

or

{
    "count":4,
    "rejectedItems": [
...
    ]
}

Error Conditions

HTTP 400 Bad Request

In the event of malformed upsert request, the system will return HTTP 400 Bad Request status.

Rejected Items

If an item was rejected due to validation, it is returned in the "rejectedItems" list of the response as shown above. The error condition is specified in "receiptType" header and message is in "receiptMessage":

{
    "count":4,
    "rejectedItems": [
       {
        "headers": {
            "category": "entity",
            "type": "Account",
            "action":"Create",
            "receiptType" : "Error",
            "receiptMessage" : "No primary key"
        },
        "data": {
            "accountClass": "/Account/accountClass[invoiced]",
          }
       }
    ]
}

Example

headers = {'content-type':'application/json', 
     'Authorization':'Bearer ' + accessToken}
resp = requests.post(options.hostUrl + 
    '/ls/api/items/upsert', data=json.dumps(data), 
    headers=headers)

Complete code example can be found here