Skip to content

Instantly share code, notes, and snippets.

@chrisneal
Forked from whatnickcodes/ngp-van-php.php
Created September 10, 2018 16:31
Show Gist options
  • Save chrisneal/c7d863fe888d2c1667c88fdda4628ae5 to your computer and use it in GitHub Desktop.
Save chrisneal/c7d863fe888d2c1667c88fdda4628ae5 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