By using the Segments API endpoint you can:
- Add or edit a Segment with an HTTP PUT request and providing the segment's information as a JSON payload.
- Delete a Segment using an HTTP DELETE request.
- Retrieve segment information for one or all Segments using an HTTP GET request.
A common use of the Segments endpoint is to keep CIOPulse segments in sync with business units or locations in your customer support software.
To use the API you must be on our Corporate or Enterprise Plan and have a 40 character API key. The key can be found in the Portal at the bottom of the Preferences page. If your key is blank, please email us at [email protected].
If you have setup IP address security in the CIOPulse Portal, the IP address of the server making the API call must be included in your list of valid IP addresses.
Authentication
All our API endpoints require HTTP basic authentication as specified in RFC 7616 from 2015. The HTTP Header of your request must contain a header field in the form of:
Authorization: Basic {credentials}
Where {credentials} is the Base64 encoding of: your Client Portal Code, a single colon, and your API Key (found in the Preferences of the Portal).
Here's a snippet of PHP script using CURL to set the authentication header.
$portal_code = 'ABC123';
$api_key = 'SMzYECYJYLpNw8PrfX8EtPO2tcP0XaKJvZ4FW5VL';
$header = array('Authorization: Basic '. base64_encode($portal_code .":". $api_key) );
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $header);
Adding or Updating Segments
To use the Segments endpoint to add or edit a Segment, issue an HTTP PUT request with this URL:
https://app.cio-pulse.com/api/v5/segments/{system_id}
{system_id} is a unique identifier for the Segment you are adding or updating, e.g. the Unique ID of a business unit or location from your customer support software.
Your PUT request must be accompanied by a JSON payload that carries the field values for the Segment you wish to add or update.
The JSON payload may only contain information for a single Segment and looks like this:
{
"segment_name": "Victoria",
"segment_code": "VIC",
"active":"y"
}
The fields allowed in the JSON payload are:
-
segment_codeis the unique Segment Code that your customer support software will pass through in thesgidparameter of the transactional survey URL, or thergid1orrgid2parameters of the relationship survey URL. -
segment_nameis the name of the Segment. -
activeis eitheryorn. Set tonfor Segments that you are no longer collecting feedback for. Inactive segments will not appear on the Customer Segment League Table or in the Segments filter of your interactive dashboards.
Add &clean to the end of your URL and any invalid characters in the segment_name (e.g. em dashes or colons) will be replaced with hyphens when the Segment is added or updated.
Your JSON must never include a backslash (\) anywhere within it. Backslashes will prevent your API call from working.
The Segment endpoint behaves as follows:
- If a Segment with this
system_idis NOT found in our database, a new Segment record will be created using the values in the JSON payload. - If a Segment with this
system_idIS found in our database, the existing Segment record will be updated as per the JSON payload.
Adding a new Segment
If a Segment with this system_id is not found in the Portal, a new Segment will be added using the values in the JSON payload.
The following fields are mandatory in the JSON when adding a new Segment:
segment_namesegment_code
The following field is optional in the JSON when adding a new Segment:
-
active(defaults toywhen omitted).
Here's a snippet of PHP script using CURL to add a new Segment:
$portal_code = 'ABC123';
$api_key = 'SMzYECYJYLpNw8PrfX8EtPO2tcP0XaKJvZ4FW5VL';
$payload_json = '{
"segment_code": "AUS",
"segment_name": "Australia"
}';
$headers = array(
'Authorization: Basic '. base64_encode($portal_code .":". $api_key),
'Content-Type:application/json',
'Content-Length: ' . strlen($payload_json)
);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl_session, CURLOPT_POSTFIELDS,$payload_json);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_URL, 'https://app.cio-pulse.com/api/v5/segments/80a45geb4faec211f6a144g18110c73d');
curl_exec($curl_session);
Note that, in this example, the System ID (used in the URL) and the Segment Code (used in the JSON payload) are not the same.
Updating a Segment
If a Segment with this system_id is found in the Portal, the existing Segment will be updated.
When updating a Segment, the fields allowed in the JSON may be set to a value or the field can be omitted from the JSON altogether:
- Set to value - Update the field to this value.
- Omitted - Leave the current field value unchanged.
For example, this JSON payload would update the Segment Name and leave the Segment Code and Active flag unchanged:
{"segment_name": "Australia & New Zealand"}
Deleting a Segment
To use the Segments endpoint to delete a Segment, issue an HTTP DELETE request with this URL:
https://app.cio-pulse.com/api/v5/segments/{system_id}
{system_id} is a unique identifier for the Segment you are deleting, e.g. the Unique ID of the business unit or location from your customer support software.
The Segment to be deleted must not have any transactional or relationship survey Responses completed for it.
Retrieving Segment information
To use the Segments endpoint to get the information for a single Segment, issue an HTTP GET request with this URL:
https://app.cio-pulse.com/api/v5/segments/{system_id}
{system_id} is a unique identifier for the Segment you wish to retrieve information for, e.g. the Primary Key value of the business unit or location from your customer support software.
To use the Segments endpoint to get the information for all Segments, issue an HTTP GET request without the system id:
https://app.cio-pulse.com/api/v5/segments
A normal response will result in an HTTP response code of 200 being returned in the header.
The segment information returned by the API looks like this (which shows 3 Segments):
{"segments":
[{"segment":{"Segment_System_ID":"SEG123","Segment_Code":"NZ","Segment_Name":"New Zealand","Active":"Y"}},
{"segment":{"Segment_System_ID":"SEG456","Segment_Code":"AUS","Segment_Name":"Australia","Active":"Y"}},
{"segment":{"Segment_System_ID":"SEG789","Segment_Code":"EMEA","Segment_Name":"EMEA","Active":"Y"}},
]}
Error Handling
A successful API call will result in one of these codes being returned in the HTTP header:
-
200Success: Segment updated or information retrieved successfully. -
201Success: Segment created. -
202Success: Segment deleted.
If there is a problem, one of these error codes will be returned in the HTTP header:
-
400Field value invalid or missing or JSON is malformed. -
401Invalid security credentials (portal code and/or API key missing or invalid). -
404A Segment with this System ID was not found. -
422Another Segment already has this Segment Code. -
500Transaction failed. Contact CIOPulse support for assistance.
In each of these error situations, a description of the error will also be returned in JSON format.
{"message":"Invalid security credentials","status":401}