Created
April 5, 2016 18:43
-
-
Save jbender/75fb232381aabd67dc4dd3097dcd326d to your computer and use it in GitHub Desktop.
Getting Started with Contactually API v2 - PHP
This file contains 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
use GuzzleHttp\Client; | |
$client = new Client([ | |
'base_uri' => 'https://api.contactually.com', | |
'headers' => [ | |
'Accept': 'application/json', | |
'Authorization': 'Bearer AUTH_TOKEN_HERE' | |
], | |
]); |
This file contains 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
$response = $client->get('/v2/me'); | |
echo $response->getBody(); |
This file contains 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
contactAttributes = [ | |
'first_name' => 'Jonathan', | |
'last_name' => 'Bender', | |
'email' => 'jbender@contactually.com' | |
]; | |
# Create the contact | |
$response = $client->request('POST', '/v2/contacts', [ | |
'json' => [ 'data' => contactAttributes ] | |
]); | |
$contact = $response->getBody()['data']; | |
# Get the available buckets | |
$bucketsResponse = $client->get('/v2/buckets'); | |
$buckets = $bucketsResponse->getBody()['data']; | |
# Add the bucket to the created contact | |
newBuckets = [[ 'id' => $buckets[0]['id'] ]]; | |
$client->request('POST', "/v2/contacts/{$contact['id']}/buckets", [ | |
'json' => [ 'data' => $newBuckets ] | |
]); |
There are also 2 variable which are declared without the $ syntax:
$contactAttributes
$newBuckets
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a problem with your code, the : should be => for key pair assignments
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.contactually.com',
'headers' => [
'Accept': 'application/json',
'Authorization': 'Bearer AUTH_TOKEN_HERE'
],
]);
should be:
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.contactually.com',
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer AUTH_TOKEN_HERE'
],
]);