Sending messages manually via the API

You can send send messages manually to your users individually using your own server and our API. This method works for push notifications, app inbox messages, email, and webhooks.

Create the message

First, you need to create and start the message in the Leanplum Dashboard. Go to the Messaging dashboard and create a new message.

Select Push Notification, Email, Webhook, or App Inbox Message. Set the Delivery to Manual. When you're finished composing the message and setting your targets, click Start.

Create the sendMessage API call

You can trigger the message using the sendMessage method of our API. If you want to send the message to the selected user even if they do not match the targets, use force = true.

You must provide a deviceID and/or a userID. If deviceID is provided, the message will be sent to the corresponding device only; if you only provide the userID, the message will be sent to all devices of the user with specified userId. Messages are queued, so they will be sent after the call completes.

If the user/device does not exist, the API call is skipped and a warning will be returned. You can modify this behavior with the createDisposition option (see below).

stringThe version of the Leanplum API to use. The current version is 1.0.6.
stringThe API method. Set this to sendMessage.
stringYour App ID. To find your appId, go to App Settings, find your app, and click Keys & Settings.
stringYour Production API key. To find your clientKey, go to App Settings, find your app, and click Keys & Settings.
required (unless you choose to use deviceId)
stringThe user ID of the targeted user. You can set this to an email address or whatever you use at your company for user IDs. Leave it blank to use the device ID. For more info, see Selecting a user.
numberThe ID of the message, found in the URL when viewing a message (e.g.{APP_ID}/messaging/{MESSAGE_ID}.
createDispositionstringThe policy that determines whether users are created by the API. Possible values:

CreateIfNeeded creates a user with the given IDs if one does not already exist.
CreateNever requires that the user already exists, otherwise the API call is skipped and a warning will be returned.

The default value for this method is CreateNever
only required if you do not include a userId
stringA unique ID for the device targeted by the call. You must provide a deviceId and/or a userId. See Selecting a user.
devModebooleanWhether the user is in Development Mode, i.e. the caller is a developer and not a user. This is important for reporting purposes. Default: false.
forcebooleanWhether to send the message regardless of whether the user meets the targeting criteria. Default: false.
valuesobjectA JSON object of key-value pairs to override Jinja values in the message. For example, if the message text is Hello {{Value "name"}}, you have {{Value "numMessages"}} new messages!, you can set values to {"name": "Bob", "numMessages": 5} to produce: Hello Bob, you have 5 new messages!

Important note: If certain values are set to null, Leanplum will return the key as a string. See more details to prevent this issue.

Where do I find the message ID?

Navigate to the message in the Leanplum dashboard. The number after the last slash in the URL is the ID.

Example: http:// ... /dashboard#/12345__164/messaging/123456789


Your API call should look something like this:{{"messageText":Hello World!"}}