-
-
Save chrisneal/c7d863fe888d2c1667c88fdda4628ae5 to your computer and use it in GitHub Desktop.
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
<?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