Trigger an event
This allows you to trigger an event for your customers
Post
bash
https://api.bunce.so/v1/events/trigger
Trigger an event.
If successful, your response includes a boolean value specifying if the event has been triggered successfully. If there is an error with any of the parameters, it will return a 422 HTTP status code with details in an error object.
Request
Body Parameters required
event_id string<uuid> required | Event name |
payload email: string<email, required if customer is absent>, customer <object required if email is absent> required | Event payload |
Payload must contain email and other paramenters keys that was added when the event was created
For parameter values with timestamp data type, values are expected to be in YYYY-MM-DDTHH:MM:SSZ (UTC) format. values for timestamp data type not in the format will be skipped.
Customer Field
The Customer
field is an required array of the customer object. The customer object should contain the following fields:
customer_id
(string): The Customer ID of the customer on your Database. This is required email is absent or null.email
(string): The email of the customer. This is required if customer_id is absent or null.first_name
(string): The first name of the customer. This is not required.last_name
(string): The last name of the customer. This is not required.phone_no
(string): The phone number of the customer. This is not required.devices
(array): An array containingdevice_type
anddevice_token
of the customer
bash
curl --request POST \
--url https://api.bunce.so/v1/events/trigger \
--header 'Content-Type: application/json' \
--header 'X-Authorization: sk_live_************************' \
--data '{
"event_id": "9bb6215c-e2b1-4e51-abff-3a96ca185088",
"payload": {
"email": "johndoe@example.com",
"customer": {
"customer_id": "7745648734",
"first_name": "Zigler",
"last_name": "Rose",
"phone_no": "+2348106489348",
"email": "esther@gmail.com"
},
"date_purchased" : "2012-09-03T14:30:00Z"
}
}'
go
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
url := "https://api.bunce.so/v1/events/trigger"
payload := strings.NewReader("{\n \"event_id\": \"9e785388-dd99-4dff-a044-f7dc58941726\",\n \"payload\": {\n \"email\": \"dami@trygreyswitch.com\",\n \"customer\": {\n \"customer_id\": \"7745648734\",\n \"first_name\": \"Zigler\",\n \"last_name\": \"Rose\",\n \"phone_no\": \"+2348106489348\",\n \"email\": \"esther@gmail.com\"\n },\n \"date_purchased\": \"2012-09-03T01:00:01Z\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Authorization", "sk_live_************************")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
js
import from 'node-fetch'
let = 'https://api.bunce.so/v1/events/trigger'
let = {
: 'POST',
: {
'X-Authorization': 'sk_live_************************',
'Content-Type': 'application/json',
},
: `{"event_id": "9bb6215c-e2b1-4e51-abff-3a96ca185088",
"payload": {
"email": "johndoe@example.com",
"customer": {
"customer_id": "7745648734",
"first_name": "Zigler",
"last_name": "Rose",
"phone_no": "+2348106489348",
"email": "esther@gmail.com"
},
"date_purchased" : "2012-09-03T14:30:00Z"
}}`,
}
(, )
.then(() => .json())
.then(() => .())
.catch(() => .('error:' + ))
php
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->append('{
"event_id": "9bb6215c-e2b1-4e51-abff-3a96ca185088",
"payload": {
"email": "johndoe@example.com",
"customer": {
"customer_id": "7745648734",
"first_name": "Zigler",
"last_name": "Rose",
"phone_no": "+2348106489348",
"email": "esther@gmail.com"
},
"date_purchased" : "2012-09-03T14:30:00Z"
}
}');
$request->setRequestUrl('https://api.bunce.so/v1/events/trigger');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'X-Authorization' => 'sk_live_************************',
'Content-Type' => 'application/json'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
java
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.bunce.so/v1/events/trigger"))
.header("X-Authorization", "sk_live_************************")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"event_id\": \"9e785388-dd99-4dff-a044-f7dc58941726\",\n \"payload\": {\n \"email\": \"dami@trygreyswitch.com\",\n \"customer\": {\n \"customer_id\": \"7745648734\",\n \"first_name\": \"Zigler\",\n \"last_name\": \"Rose\",\n \"phone_no\": \"+2348106489348\",\n \"email\": \"esther@gmail.com\"\n },\n \"date_purchased\": \"2012-09-03T01:00:01Z\"\n }\n}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Response
json
{
"success": true,
"data": true,
"message": "Event successfully triggered"
}