Skip to content

Instantly share code, notes, and snippets.

@jbender
Created April 5, 2016 18:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbender/75fb232381aabd67dc4dd3097dcd326d to your computer and use it in GitHub Desktop.
Save jbender/75fb232381aabd67dc4dd3097dcd326d to your computer and use it in GitHub Desktop.
Getting Started with Contactually API v2 - PHP
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.contactually.com',
'headers' => [
'Accept': 'application/json',
'Authorization': 'Bearer AUTH_TOKEN_HERE'
],
]);
$response = $client->get('/v2/me');
echo $response->getBody();
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 ]
]);
@aaronwi
Copy link

aaronwi commented Apr 3, 2017

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'

],
]);

@CCDevelopment
Copy link

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