Jump to content

Recommended Posts

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!");

}

?>

Link to comment
https://forums.phpfreaks.com/topic/284235-php-curl-using-json-413-error/
Share on other sites

413

 

The requested URL returned error: 413 Request Entity Too Large

 

object(stdClass)#1 (6) { ["userId"]=> string(8) "###" ["groupId"]=> string(6) "###" ["orgId"]=> string(4) "###" ["contactName"]=> string(13) "###" ["userName"]=> string(6) "###" ["attribute"]=> string(5) "Array"

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.