Batching requests with multi

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 the multi 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:

paramdescription
appIdrequired
The application ID. To find yours, select your app in the navigation column, and click Edit Apps. Under Keys, click Show.
clientKeyrequired
The Production key for your Leanplum App.
apiVersionrequired
The version of the Leanplum API to use. The current version is 1.0.6.
timerequired
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.
datarequired
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.