Pre-requisites

Create User Profile

Send Event

You can send event to Suprsend platform by using the supr_client.track_event method. When you call supr_client.track_event, the SDK internally makes an HTTP call to SuprSend Platform to register this request, and you’ll immediately receive a response indicating the acceptance status. The actual processing/execution of event happens asynchronously.

from suprsend import Suprsend
from suprsend import Event

supr_client = suprsend.Suprsend("workspace_key", "workspace_secret")
 
distinct_id = "distinct_id" # Mandatory, Unique id of user in your application
event_name = "event_name"   # Mandatory, name of the event you're tracking
brand_id = "brand_id"   # Mandatory, name of the event you're tracking

# Properties:  Optional, default=None, a dict representing event-attributes
properties = {                                       
"key1":"value1",
"key2":"value2"
} 

event = Event(distinct_id=distinct_id, event_name=event_name, properties=properties, idempotency_key="__uniq_request_id__", brand_id="default")

# Track event
response = supr_client.track_event(event)
print(response)
ParameterDescriptionFormatObligation
distinct_iddistinct_id of user performing the eventint, bigint, string, UUIDmandatory
event_namestring identifier for the event like product_purchasedstringmandatory
propertiesa dictionary representing event attributes like first_name Event properties can be used to pass template variables in case of event based triggerDictionaryoptional

Event naming guidelines:

Event Name or Property Name should not start with or , as we have reserved these symbols for our internal events and property names.

Idempotent requests

SuprSend supports idempotency to ensure that requests can be retried safely without duplicate processing. If Suprsend receives and processes a request with an idempotency_key, it will skip processing requests with same idempotency_key for next 24 hours. You can use this key to track webhooks related to workflow notifications.

Idempotency key should be unique that you generate for each request. You may use any string up to 255 characters in length. Any space at start and end of the key will be trimmed.

Here are some common approaches for assigning idempotency keys:

  • Generate a random UUID for each request.
  • Construct the idempotency key by combining relevant information about the request. This can include parameters, identifiers, or specific contextual details that are meaningful within your application. For example, you could concatenate the user ID, action, and timestamp to form an idempotency key like user147-new-comment-1687437670
  • Request-specific Identifier: If your request already contains a unique identifier, such as an order ID or a job ID, you can use that identifier directly as the idempotency key.

Add file attachment in event (for email)

To add one or more Attachments to a Notification (viz. Email), you can just append the filepath of attachment to the event instance.

  • Call event.add_attachment() for each file with an accessible URL.
  • Ensure that file_path is a publicly accessible URL. Since event API size can’t be > 100 KB, local file paths can’t be passed in event attachment.
from suprsend import Event

distinct_id = "0fxxx8f74-xxxx-41c5-8752-xxxcb6911fb08"
event_name = "invoice_generated" 
properties = {...}

event = Event(distinct_id=distinct_id, event_name=event_name, properties=properties)

# this snippet can be used to add attachment to event
file_path = "https://www.adobe.com/sample_file.pdf"
event.add_attachment(file_path)

response = supr_client.track_event(event)
print(response)

Please add public accessible URL only as attachment file otherwise it will throw an error 404 not found and workflow will not be triggered

Bulk Event trigger

You can use Bulk API to send multiple events. Use .append() on bulk_events instance to add however-many-records to call in bulk.

from suprsend import Event

bulk_ins = supr_client.bulk_events.new_instance()
# Example
e1 = Event("distinct_id1", "event_name1", {"k1": "v1"}) # Event 1
e2 = Event("distinct_id2", "event_name2", {"k2": "v2"}) # Event 2

# --- use .append on bulk instance to add one or more records
bulk_ins.append(e1)
bulk_ins.append(e2)
# OR
bulk_ins.append(e1, e2)

# -------
response = bulk_ins.trigger()
print(response)

Bulk API is supported in SuprSend python-sdk version 0.2.0 and above. If you are using an older version, please upgrade to the latest SDK version.