Last active
August 29, 2015 14:24
-
-
Save bonnie/c6ddf6a1786f65308c5a to your computer and use it in GitHub Desktop.
Setting Custom Attributes via the enroll 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 = '/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" | |
| // ] | |
| // } | |
| // ] | |
| // } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment