Last active
August 29, 2015 14:24
-
-
Save bonnie/c68ca255cbee2ee0a296 to your computer and use it in GitHub Desktop.
Editing Custom Attributes via the update_attributes End Point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$secret_key = YOUR_SECRET_KEY_HERE; | |
$uuid = YOUR_UUID_HERE; | |
$endpoint = '/data/customer/update_attributes.json'; | |
$email = "[email protected]"; | |
$url_data = array( | |
"uuid" => $uuid, | |
"email" => $email | |
); | |
$post_data = array( | |
array( | |
"op" => "add", | |
"path" => "/zip code", | |
"value" => "90210" | |
), | |
array( | |
"op" => "add", | |
"path" => "/pet count/dogs", | |
"value" => 1 | |
), | |
array( | |
"op" => "remove", | |
"path" => "/how did you hear" | |
), | |
array( | |
"op" => "replace", | |
"path" => "/gender", | |
"value" => "male" | |
), | |
array( | |
"op" => "add", | |
"path" => "/interests/0", | |
"value" => "dog training" | |
) | |
); | |
$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\nAccept: 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" | |
// ] | |
// } | |
// ] | |
// } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment