cwiddowson Posted November 25, 2013 Share Posted November 25, 2013 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!"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/ Share on other sites More sharing options...
cwiddowson Posted November 25, 2013 Author Share Posted November 25, 2013 413 The requested URL returned error: 413 Request Entity Too Large object(stdClass)#1 (6) { ["userId"]=> string( "###" ["groupId"]=> string(6) "###" ["orgId"]=> string(4) "###" ["contactName"]=> string(13) "###" ["userName"]=> string(6) "###" ["attribute"]=> string(5) "Array" Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1459883 Share on other sites More sharing options...
cwiddowson Posted November 25, 2013 Author Share Posted November 25, 2013 I changed the json to json_raw since it was already json, but however now I'm getting a CURL (401) The requested URL returned error: 401 Unauthorized Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1459886 Share on other sites More sharing options...
QuickOldCar Posted November 25, 2013 Share Posted November 25, 2013 You can try increasing the following values in your php.ini file until it works. The values below are examples. memory_limit = 32Mupload_max_filesize = 2Mpost_max_size = 3M Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1459888 Share on other sites More sharing options...
cwiddowson Posted November 25, 2013 Author Share Posted November 25, 2013 Thanks for the response, the problem I seem to be having now is: 401The requested URL returned error: 401 Unauthorized Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1459891 Share on other sites More sharing options...
cwiddowson Posted November 25, 2013 Author Share Posted November 25, 2013 Got the 401 fixed now I'm getting a (405) The requested URL returned error: 405 Method Not Allowed Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1459893 Share on other sites More sharing options...
QuickOldCar Posted November 25, 2013 Share Posted November 25, 2013 You are using POST, server expects GET , if is not that is your credentials. Quote Link to comment https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/#findComment-1460080 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.