Skip to content

Instantly share code, notes, and snippets.

@whatnickcodes
Created May 26, 2015 18:25
Show Gist options
  • Save whatnickcodes/bb389d0e4a2c962796a6 to your computer and use it in GitHub Desktop.
Save whatnickcodes/bb389d0e4a2c962796a6 to your computer and use it in GitHub Desktop.
<?php
// TO DO: ADD VALIDATION ON EMAIL AND ZIP BEFORE REQUEST
$email = $_POST['email'];
$zip = $_POST['zip'];
$url = 'https://api.myngp.com/v2/contacts/findOrCreate';
$post_data = array(
'type' => 'INDIVIDUAL',
'emails' => [
[
'address' => $email,
'type' => 'MAIN'
]
],
'address' => [
[
'postalCode' => $zip,
'type' => 'MAIN'
]
],
'contactCodes' => [
[
'contactCodeId' => 1577 // Basic Website Signup (no NGP ActionTag)
]
]
);
$post_data = json_encode($post_data);
$username = 'apiuser';
$password = 'abc123';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
)
);
$output = curl_exec($ch);
curl_close($ch);
// TO DO: Output as JSON response for front-end app
var_dump(json_decode($output));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment