Add Subscriber to Segment
This endpoint allows adding a subscriber to a segment using the subscriber_hash
. This call accepts form-encoded request bodies and returns responses in JSON format.
info
In some APIs, the term subscriber_hash
is used. However, the same reference is called subscriber_id
in the web SDK. As a result:
- Web SDK: consistently uses
subscriber_id
. - API: opts for
subscriber_hash
.
POST
https://api.pushengage.com/apiv1/segments/addSegmentWithHash
Request Parameters
Parameter Name | Type | Required | Description |
---|---|---|---|
segment_id | Number | Yes | The unique identifier generated when a segment is created. |
subscriber_hash | String[] | Yes | An array of unique hashes to identify subscribers. The maximum array size is 500. |
Response Object
Property Name | Type | Required | Description |
---|---|---|---|
success | Boolean | Yes | Indicates whether the push response was successful. Acceptable values are true or false . |
message | String | Yes | Conveys the reason for the result, be it success or failure. |
Example
Request
- cURL
- PHP
curl -X POST -H "api_key: <your_pushengage_api_key>" -H "Content-Type: application/x-www-form-urlencoded" -d 'segment_id=<Segment Id>&subscriber_hash[0]=<subscriber_hash>&subscriber_hash[1]=<subscriber_hash>' "https://api.pushengage.com/apiv1/segments/addSegmentWithHash"
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.pushengage.com/apiv1/segments/addSegmentWithHash",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "segment_id=<Segment Id>&subscriber_hash[0]=<subscriber_hash>&subscriber_hash[1]=<subscriber_hash>",
CURLOPT_HTTPHEADER => array(
"api_key: <your_pushengage_api_key>",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Response
- 200 OK
- 401 Unauthorized
- 400 Bad Request
{
"message": "Segment Addition to Subscriber Hashes is Successful",
"success": true
}
{
"success": false,
"message": "API KEY Invalid"
}
{
"message": "Enter a valid segment id",
"success": false
}
{
"message": "Your enter segment id does not exist",
"success": false
}