Below is PHP using CURL with JSON to POST data to the MemberClicks API. I keep getting a 413 error when trying to process the page. I've tried a few things, but none seem to work. So far I don't get and syntax errors just on the 413.
<?php
if (!empty($_POST['userid']) && !empty($_POST['username']) && $_POST['data']=="Update") {
$dateATOM = date(DATE_ATOM);
$groupid = "12345";
$org = "ABCco";
$userid = $_POST['userid'];
$username = $_POST['username'];
$contactname = $_POST['contactname'];
$email = $_POST['email'];
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$businessaddress1 = $_POST['businessaddress1'];
$businessaddress2 = $_POST['businessaddress2'];
$businesscity = $_POST['businesscity'];
$businessstate = $_POST['businessstate'];
$businessinternationalstate = $_POST['businessinternationalstate'];
$businesscountry = $_POST['businesscountry'];
$businesszip = $_POST['businesszip'];
$companyname = $_POST['companyname'];
$title = $_POST['title'];
$businessphone = $_POST['businessphone'];
$mobilephone = $_POST['mobilephone'];
$extension = $_POST['extension'];
$fax = $_POST['fax'];
$url = $_POST['url'];
// Establish
$url = 'https://####.memberclicks.net/services/auth';
$data = 'apiKey=123&username=user&password=pass';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$httpHeaders[] = "Accept: application/json";
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
curl_close($ch);
$token = $jsonResult->token;
// end -->
$raw_json ='{"userId":
"'.$userid.'","groupId":"'.$groupid.'","orgId":"'.$org.'","contactName":
"'.$contactname.'","userName":
"'.$username.'","attribute":[{"userId":
"'.$userid.'","attId":"528954","attTypeId":"10",
"attData":
"'.$username.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"528955","attTypeId":"16",
"attData":
"'.$contactname.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"528950","attTypeId":"1",
"attData":
"'.$email.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529209","attTypeId":"2",
"attData":
"'.$firstname.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529210","attTypeId":"7",
"attData":
"'.$middlename.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529211","attTypeId":"3",
"attData":
"'.$lastname.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529213","attTypeId":"28",
"attData":
"'.$businessaddress1.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529214","attTypeId":"29",
"attData":
"'.$businessaddress2.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529215","attTypeId":"30",
"attData":
"'.$businesscity.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529216","attTypeId":"31",
"attData":
"'.$businessstate.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529240","attTypeId":"7",
"attDate":
"'.$businessinternationalstate.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529217","attTypeId":"33",
"attData":
"'.$businesscountry.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529218","attTypeId":"32",
"attData":
"'.$businesszip.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529219","attTypeId":"7",
"attData":
"'.$companyname.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529220","attTypeId":"7",
"attData":
"'.$title.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529221","attTypeId":"5",
"attData":
"'.$businessphone.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529244",
"attData":
"'.$mobilephone.'","attTypeId":"5","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529222","attName":"Extension",
"attData":
"'.$extension.'","lastModify":
"'.$dateATOM.'"},{"userId":
"'.$userid.'","attId":"529223","attTypeId":"14",
"attData":
"'.$fax.'","lastModify":
"'.$dateATOM.'"},
{"userId":
"'.$userid.'","attId":"529228","attTypeId":"15",
"attData":
"'.$url.'","lastModify":
"'.$dateATOM.'"}]}';
$json = json_decode($raw_json);
$url2 = 'https://####.memberclicks.net/services/user/'.$userid.'/?includeAtts=true';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_POST, true);
$httpHeaders[] = "Accept: application/json";
$httpHeaders[] = "Authorization: ".$token;
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders );
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$results = curl_exec($ch);
if (curl_errno($ch)) {
echo "<h2>Yes</h2>";
print "<strong>".curl_getinfo( $ch, CURLINFO_HTTP_CODE )."</strong><br><br>";
print "<strong>".curl_error($ch)."</strong><br><br>";
echo "<hr><p>".var_dump($json)."</p>";
} else {
echo "<h2>No</h2>";
print curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close($ch);
echo "<hr><p>".var_dump($json)."</p>";
//print curl_error($ch);
//echo "<p>".$raw_json."</p>";
//header("location: getAll.php?error=Something Happened!");
}
return $results;
} else {
header("location: getAll.php?error=Nothing Happened!");
}
?>