How to Send Events to the SendPulse

You can send events to your system using the SendPulse API. Sending requests is possible with and without authorization.

To send an event, you need the following:

  • a request URL;
  • a contact email address or phone number — these are required parameters used to identify contacts;
  • optional contact parameters used as variables to personalize messages;
  • automation_id, an optional system parameter used to identify the flow to which you send the request data.

Copy a URL

Go to the “Events Manager” section, create or choose your event, and click its name.

Select a request method.

Using the SendPulse library on GitHub, pass the event with authorization and the URL from the "REST API POST" tab. You can get the authorization keys in the "API" tab of your account settings.

If you don’t use the library and need to pass events without authorization, copy the URL from the "POST raw" or “POST form-data” tabs.

Copy your URL in the corresponding tab.

Prepare the Request Body

Pass the data using custom or global variables.

Make sure to pass the email or phone variables with the "String" parameter type so that SendPulse identifies your contacts and triggers the event.

Having other variables in the request is optional. They are only necessary if used in automation flow messages.

Identify an Automation Flow by Its ID

You can also send a flow ID via the automation_id optional parameter to identify requests and send personalized data to different flows with the same event link.

Note that you should add automation_id with the "Number" parameter type outside the array.

You don't need to set up the automation_id parameter when creating an event.

To get the automation_id value, go to your flow page in the "Dashboard" tab and copy the numeric value after /flow/id/ in its address bar.

For example, with a flow ID, you can send a triggered email from an online store in different languages. To communicate with your English-speaking customers, you will have the English email version in one flow and add it and a manager name with a sender email address to your CRM system. You will have the Polish email version in another flow, save it to another CRM, and use another sender's name.

Request Samples

Without Authentication

PHP with cURL

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://events.sendpulse.com/events/id/eb561baa181247d1cd378c4ead632877/7043663',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "email": " test1@test1.com",
  "phone": "+123456789",
  "product_name": "product_name value",
  "product_id": 123,
  "product_link": "product_link value",
  "product_price": "product_price value",
  "product_img_url": "product_img_url value",
  "event_date": "2021-05-28"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Python

import requests

url = "https://events.sendpulse.com/events/id/eb561baa181247d1cd378c4ead632877/7043663"

payload="{\n  \"email\": \"test1@test1.com\",\n  \"phone\": \"+123456789\",\n  \"product_name\": \"product_name value\",\n  \"product_id\": 123,\n  \"product_link\": \"product_link value\",\n  \"product_price\": \"product_price value\",\n  \"product_img_url\": \"product_img_url value\",\n  \"event_date\": \"2021-05-28\"\n}"
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

With Authorization

PHP

<?php

use Sendpulse\RestApi\ApiClient;
use Sendpulse\RestApi\Storage\FileStorage;

define('API_USER_ID', '');
define('API_SECRET', '');
define('PATH_TO_ATTACH_FILE', __FILE__);

$SPApiClient = new ApiClient(API_USER_ID, API_SECRET, new FileStorage());

// Start event automation360
$eventName = 'registration';
$variables = [
    "email" => "test1@test1.com",
    "phone" => "+123456789",
    "var_1" => "var_1_value"
];

var_dump($SPApiClient->startEventAutomation360($eventName,$variables));

Read more: GitHub: SendPulse REST client library.

Python

# -*-coding:utf8-*-

""" SendPulse REST API usage example

Documentation:
    https://login.sendpulse.com/manual/rest-api/
    /api
"""

from pysendpulse.pysendpulse import PySendPulse

if __name__ == "__main__":
    REST_API_ID = ''
    REST_API_SECRET = ''
    TOKEN_STORAGE = 'memcached'
    MEMCACHED_HOST = '127.0.0.1:11211'
    SPApiProxy = PySendPulse(REST_API_ID, REST_API_SECRET, TOKEN_STORAGE, memcached_host=MEMCACHED_HOST)

    # Start event
    params = {
        "email": "test1@test1.com",
        "phone": "+123456789",
        "var_1": "var_1_value"
        }

    SPApiProxy.send_event('registration', params);

Read more: GitHub: SendPulse REST client library.

Rate this article about "How to Send Events to the SendPulse"

User Rating: 5 / 5

    Popular in Our Blog

    Try SendPulse today for free