Created
August 23, 2016 20:31
-
-
Save jeremyjclarke/5954c5f90969807f41724356314c8fe2 to your computer and use it in GitHub Desktop.
Merge Document from PHP
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 | |
//$user = User information from app | |
//$account = Account information from app | |
$customerInfo = array( | |
'FirstName' => $user->first_name, | |
'LastName' => $user->last_name, | |
'Email' => $user->email, | |
'Company' => $account->company, | |
'State' => $account->state, | |
'Address' => $account->street_address.', '.$account->city.', '.$account->state.' '.$account->zip, | |
); | |
$mergeUrl = 'https://www.webmerge.me/merge/12345/abcdef'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $mergeUrl); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerInfo)); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json' | |
)); | |
$res = curl_exec($ch); | |
$response = json_decode($res, true); | |
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
if($status == 201){ | |
//success | |
}else{ | |
die('Error: '.$response['error']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment