Sending messages manually via the API

You can send send push notifications manually to your users individually using your own server and our API. First, you need to create and start the message in the Leanplum Dashboard.

Create the message

To create the push notification, go to the Messaging dashboard and create a new message. Be sure to select Push Notification and set the Delivery to "Manual". Click "Start" when you're finished composing the message and setting your targets. It should be similar to this: 

manual-push.png

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 only userId is provided, 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).

parameter type description
apiVersion
required
string The version of the Leanplum API to use. The current version is 1.0.6.
action
required
string The API method. Set this to sendMessage.
appId
required
string Your App ID. To find your appId, go to App Settings, find your app, and click Keys & Settings.
clientKey
required
string Your Production API key. To find your clientKey, go to App Settings, find your app, and click Keys & Settings.
userId
required - unless you choose to use deviceId
string The 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 users and devices.
messageId
required
number The ID of the message, found in the URL when viewing a message (e.g. www.leanplum.com/dashboard#/{APP_ID}/messaging/{MESSAGE_ID}.

createDisposition string

The 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.

deviceId
only required if you do not include a userId
string A unique ID for the device targeted by the call. You must provide a deviceId and/or a userId. See users and devices.
devMode boolean Whether 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.
force boolean Whether to send the message regardless of whether the user meets the targeting criteria. Default: false.
values object A JSON object of key-value pairs to override Jinja values in the message. For example, if the message text is Hello {{"name"}}, you have {{"numMessages"}} new messages!, you can set values to {"name": "Bob", "numMessages": 5} to produce: Hello Bob, you have 5 new messages!.

 

Example

Your API call should look something like this:

https://www.leanplum.com/api?appId=yourAppIdHere&clientKey=yourClientKeyHere&action=sendMessage&apiVersion=1.0.6&messageId=messageId&userId=theUserIdOfTheUser&values={{"messageText":Hello World!"}}

Was this article helpful?
Have more questions? Submit a request