Creating a Segment#

Getting Started#

Introduction

This endpoint is used to create a segment. The request method of this call needs to be "POST". Segment name has to be sent as POST parameters to the API endpoint.

Request URL

 https://api.pushengage.com/apiv1/segments

Method

  POST

Request Parameters

Required Parameters

Parameter Name Parameter Type Description
segment_name String This defines the segment name. You can send notifications to particular segment.

Response Objects

Required Object

Property Name Property Type Description
success Boolean To denote whether the request succeeded or not. Values can be 'true' or 'false'.
segment_id String To denote the id of segment. Value is always unique.

Optional Object

Property Name Property Type Description
message String Present in case of failure. Used to denote reason of failure.

Creating a First Segment#

This endpoint is used to create a segment. This request requires parameter segment_name.

Example#

Request

  • cURL
  • PHP
curl -X POST 
-H "api_key: <your_pushengage_api_key>" 
-H "Content-Type: application/x-www-form-urlencoded" 
-d 'segment_name=coupon' 
"https://api.pushengage.com/apiv1/segments"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/segments",
      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_name=coupon",
      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
{
  "success": true,
  "segment_id": 98756
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "ENTER A VALID SEGMENT NAME",
  "success": false
}