Skip to content

Instantly share code, notes, and snippets.

@rewandy
Created December 3, 2013 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewandy/d769d140d2079c4cde3e to your computer and use it in GitHub Desktop.
Save rewandy/d769d140d2079c4cde3e to your computer and use it in GitHub Desktop.
An example of how to create a history event using the REW CRM API
<?php
// REW CRM API Key
define('REW_API_KEY', '7220899b054d5ed760f80237a6c0XXXXXXXX30aa2d61235e1efxde52676f1');
// cURL resource
$ch = curl_init();
// Auth headers
$headers = array(
'X-REW-API-Key: ' . REW_API_KEY,
);
// API Request URL
$request_url = 'http://www.example.com/api/crm/v1/leads/johns@example.com/events';
// POST params
$post_params = array(
'type' => 'Action',
'subtype' => 'FormSubmission',
'details' => array(
'page' => 'http://www.example.com/contact.html',
'form' => 'My third-party contact form',
'data' => array(
'first_name' => 'John',
'last_name' => 'Smith',
'email' => 'johns@example.com',
'some_other_field' => 'Test Data',
'comments' => "Hello there!\nThese words are on a new line." . PHP_EOL . 'And so is this!',
),
),
);
// Turn POST parameters into a URL-encoded string
$post_params = http_build_query($post_params);
// cURL options
$options = array(
CURLOPT_URL => $request_url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_USERAGENT => 'apiClient/1.0',
CURLOPT_TIMEOUT => 60,
CURLINFO_HEADER_OUT => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post_params,
CURLOPT_HTTPHEADER => $headers,
);
// Set cURL options
curl_setopt_array($ch, $options);
// Execute request & get response
$output = curl_exec($ch);
// Close resource
curl_close($ch);
// Print raw output from API
echo $output . PHP_EOL;
// Print decoded JSON from API
$json = json_decode($output, true);
var_dump($json);
@rewandy
Copy link
Author

rewandy commented Dec 3, 2013

To create a newline, you can either use a \n inside a string wrapped in double-quotes, or concatenate any string with PHP_EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment