Jump to content
X2Community Forums

Basic Test for Web Lead Capture: Missing or malformed data sent to server. 400


Recommended Posts

I'm new to the community so I'm probably missing something basic.  Any help would be great.

 

I'm trying to create a new contact using a basic php page with hard coded data.

I'm getting back 'Missing or malformed data sent to server.' but I have no idea what the server doesn't like.

 

{"httpHeaders":{"Content-Type":"application\/json; charset=utf-8"},"message":"Missing or malformed data sent to server.","error":true,"status":400}

 

I've attached the full contents of my php file:

 

<?php

$username = "admin";
$password = "9...Q";
$contact = array(
                 "firstName" => "Walt",
                 "lastName" => "White",
"email" => "walter.white@sandia.gov",
                 "visibility" => 1
                );
echo "<p>curl init</p>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8;"));
echo "<p>".count($contact)."</p>";
curl_setopt($ch, CURLOPT_POST, count($contact));
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_POSTFIELDS, "'firstName':'John','lastName':'Smith','visibility':1,'email':'johnsmith@example.com'");
//curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($contact));
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
 
//Actual Call to Server
$server_output = curl_exec ($ch);
$headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);
curl_close ($ch);
echo "<p>curl closed</p>";
 
echo "</br>";
echo $headers;
echo "</br></br>";
echo $server_output;
echo "</br></br>";
?>
 
You may notice that I tried using $contact and also tried directly entering the text in CURLOPT_POSTFIELDS.  Both got the same result.
Link to post
Share on other sites

Fixed!

<?php
$username = "admin";
$password = "<userKey>";
$contact = array(
    "firstName" => "Walt",
    "lastName" => "White",
    "email" => "walter.white@sandia.gov",
    "visibility" => 1
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8;")); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); 
$data = json_encode ($contact);
curl_setopt($ch, CURLOPT_POST, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
 
//Actual Call to Server
$server_output = curl_exec ($ch);
?>
  • Like 2
Link to post
Share on other sites
  • 10 months later...
  • 3 years later...

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...