<?php
$secret_key = YOUR_SECRET_KEY_HERE;
$uuid = YOUR_UUID_HERE;
$endpoint = '/api/enroll.json';
$email = "katlover@katloverstogether.com";
echo $email . "<br><br>";
$url_data = array(
"uuid" => $uuid,
"email" => $email,
"channel" => "online"
);
$post_data = array(
"custom_attributes" => array(
"gender" => "female",
"pet count" => array(
"cats" => 150
),
"interests" => array(
"breeding",
"fish circus"
),
"how did you hear" => "komodo dragon"
)
);
$raw_post = json_encode($post_data);
$query_string = http_build_query($url_data);
$path = $endpoint . "?" . $query_string;
$string_to_hash = $secret_key . $path . $raw_post;
$path = $path . "&sig=" . md5($string_to_hash);
$url = 'https://api-stage.500friends.com' . $path;
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $raw_post
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
// debugging
var_dump($result);
// custom attribute validation spec for this example
//
// {
// "custom_attributes": [
// {
// "path": "/zip code",
// "type": "string"
// },
// {
// "path": "/gender",
// "type": "string",
// "accepted_value": [
// "male",
// "female",
// "other"
// ]
// },
// {
// "path": "/interests",
// "type": "string",
// "accepted_value": [
// "dog training",
// "breeding",
// "fish circus"
// ]
// },
// {
// "path": "/pet count/dogs",
// "type": "integer",
// "accepted_range": {
// "min": 0,
// "max": 20
// }
// },
// {
// "path": "/pet count/cats",
// "type": "integer",
// "accepted_range": {
// "min": 0,
// "max": 500
// }
// },
// {
// "path": "/pet count/fish",
// "type": "integer",
// "accepted_range": {
// "min": 0,
// "max": 100
// }
// },
// {
// "path": "/pet count/komodo dragon",
// "type": "integer",
// "accepted_range": {
// "min": 0,
// "max": 1500
// }
// },
// {
// "path": "/pet count/other",
// "type": "integer",
// "accepted_range": {
// "min": 0,
// "max": 350
// }
// },
// {
// "path": "/how did you hear",
// "type": "string",
// "accepted_value": [
// "magazine advertisement",
// "radio advertisement",
// "online advertisement",
// "word of mouth",
// "komodo dragon",
// "other"
// ]
// }
// ]
// }
?>
Setting Custom Attributes via the enroll End Point
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.