<?php
$secret_key = YOUR_SECRET_KEY_HERE;
$uuid = YOUR_UUID_HERE;
$endpoint = '/data/customer/update_attributes.json';
$email = "katlover@katloverstogether.com";
$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"
// ]
// }
// ]
// }
?>
Editing Custom Attributes via the update_attributes 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.