Use a multi
call to batch multiple API requests
To improve performance and reduce your billable API calls, we can created a way for you to batch multiple API requests for the same users as much as possible (see more on Reducing billable requests).
Concurrent Requests
While Leanplum processes a successful
multi
call, concurrent requests for these users (via the SDK or API) will be queued and completed after themulti
batch completes.
Sending the request
The first step in batching API actions into the multi
call is to make a POST request to https://api.leanplum.com/api?action=multi
. To complete the call, you will need to include the following parameters in the body of the request:
param | description |
---|---|
appId | required The application ID. To find yours, select your app in the navigation column, and click Edit Apps. Under Keys, click Show. |
clientKey | required The Production key for your Leanplum App. |
apiVersion | required The version of the Leanplum API to use. The current version is 1.0.6. |
time | required The time at which the request was issued (UNIX time). This is used to resolve the time difference between Leanplum and the API caller when computing the times of events. |
data | required A JSON-encoded list of API methods to execute. All methods must be for the same app referred to by the appId parameter. Each data object must include the required arguments for its API action. |
Each nested object in the data
array is an individual API action, and must include the required parameters for that method. You'll need to reference each nested API method's documentation for info on required parameters and options. Below is an example cURL call:
curl --location -g --request POST 'https://api.leanplum.com/api?action=multi' \
--header 'Content-Type: application/json' \
--data-raw '{
"appId": "YOUR_APP_ID",
"clientKey": "YOUR_PROD_KEY",
"apiVersion": "1.0.6",
"time": 1375295890,
"data": [
{
"action": "start",
"time": 1375295825,
"userAttributes": {
"Gender": "Male",
"Age": 25
},
"userId": "user1"
},
{
"action": "track",
"time": 1375295830,
"event": "Level Complete",
"params": {
"Level": 1,
"Score": 100
},
"userId": "user1"
}
]
}'
Response
Each individual action will also have its own response; some may be successful, while some may have warnings or others with errors. The index of the response will match the index of the request in the data
array.
For the example above, if we pass a bad string as the action
in the second batched request, we would get the following response:
{
"response": [
{
"success": true
},
{
"success": false,
"error": {
"message": "Action not found"
}
}
]
}
The 'multi' call method is limited to 50 users and/or 500 actions in a single call. All calls in a batch with more than this will be ignored and the server will return a 403 status. Each unique user lookup in a request is a billable API call. See billing and costs for more.