post_easy_dispatches
POST /easy_dispatches
Send a survey to a specified email address
- Rails
- php
require 'rest-client'
RestClient::Request.execute method: :post,
url: 'https://api.diduenjoy.com/api/v1/easy_dispatches',
user: 'PUT-YOUR-API-KEY-HERE',
headers: {
content_type: 'application/json'
},
payload: {
email: 'client@example.com', # or phone_number: '+336xxxxxxxx'
survey_id: 'YOUR-SURVEY-ID-HERE',
template_id: 'YOUR-TEMPLATE-ID-HERE',
segments: {
language: 'EN',
scheduled_at: '2022-04-18 15:07:00',
gender: 'Mister',
name: 'Rick Sanchez',
interests: 'Science',
},
dispatch_probability: 0.5
}.to_json
# => {
# "id": "DISPATCH-ID",
# "email": "client@example.com", # or "phone_number": "+336xxxxxxxx"
# "survey_id": "YOUR-SURVEY-ID-HERE",
# "template_id": "YOUR-TEMPLATE-ID-HERE",
# "segments": {
# "language": "EN",
# "scheduled_at": "2022-04-18 15:07:00",
# "gender": "Mister",
# "name": "Rick Sanchez",
# "interests": "Science"
# },
# "dispatch_probability": 0.5
# }
$api_key = 'YOUR-API-KEY-HERE';
$survey_id = 'YOUR-SURVEY-ID-HERE';
$template_id = 'YOUR-TEMPLATE-ID-HERE',
$email = 'client@example.com'; // or $phone_number = '+336xxxxxxxx'
$date = '2022-04-18 15:07:00';
$payload = array(
'email' => $email, // or 'phone_number' => $phone_number
'survey_id' => $survey_id,
'template_id' => $template_id,
'segments' => array(
'language' => 'EN',
'scheduled_at' => $date,
'gender' => 'Mister',
'name' => 'Rick Sanchez',
'interests' => 'Science'
),
'dispatch_probability' => 0.5
);
$ch = curl_init('https://api.diduenjoy.com/api/v1/easy_dispatches');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_USERPWD => "$api_key:",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POSTFIELDS => json_encode($payload)
));
// Send the request
$response = curl_exec($ch);
// => {
// "id": "DISPATCH-ID",
// "email": "client@example.com", // or "phone_number":"+336xxxxxxxx"
// "survey_id": "YOUR-SURVEY-ID-HERE",
// "template_id": "YOUR-TEMPLATE-ID-HERE",
// "segments": {
// "language": "EN",
// "scheduled_at": "2022-04-18 15:07:00",
// "gender": "Mister",
// "name": "Rick Sanchez",
// "interests": "Science"
// },
// "dispatch_probability": 0.5
// }
note
segments
languageandscheduled_atare special segments.gender,nameandinterestsare user defined.
attributes
| attribute | description | |
|---|---|---|
| email string | either email or phone number or no_dispatch required | email address to which send the survey |
| phone_number string | either email or phone number or no_dispatch required | phone number to which the survey will be send. The international format should be used (ex: +33) |
| survey_id string | required | id of the survey |
| template_id string | either template_id or no_dispatch required | id of the template |
| segments hash { string: string } | custom data associated with the survey | |
| dispatch_probability string | probability for the survey to be sent | |
| no_dispatch boolean | set it to disable sending of the survey and only create an new feedback that you could dispatch by your own means |
Segments
All segments are dynamically created, you can name them as you want.
There is 2 exceptions:
language: if available, force the survey language, should be a ISO 639-1 code (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)scheduled_at: schedule the dispatch, should be formated as ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601)
Remarks
- The dispatch mode is specified by which of the parameters email or phone_number is set. One and only one of them should be specified