I'm trying to post json data using cURL to
an API script that submits the data to an
application. I use file_get_contents('php://input')
and the data does not get submitted to the application
But if I type in an actual email address in the "contact_email"
in the API it submits the email to the application.
Here is the cURL script first:
`
$data = '
{
"customer":
{
"first_name":"John",
"last_name":"Smith",
"email":"[email protected]",
"phone_number":"2125555555",
"billing_address":"212 Any Street",
"billing_city":"Any City",
"billing_state":"New York",
"billing_zip":"10012",
"billing_country":"USA"
}
}
';
$ch = curl_init('http://example.com/acadd.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
`
and here is the API script it posts to:
<?php
$json_data = file_get_contents('php://input');
$cart = json_decode( $json_data );
$email = $cart->customer->email .
// Set up an object instance using our PHP API wrapper.
define("AC_URL", "https://account.api-us1.com");
define("AC_API_KEY", "api key");
require_once("./ac-api-php/includes/ac.class.php");
$ac = new AC(AC_URL, AC_API_KEY);
$post_data = array(
"contact_email" => $email , // include this or contact_id
"automation" => "9", // one or more
);
$response = $ac->api("automation/contact/add", $post_data);
echo "<pre>";
print_r($response);
echo "</pre>";?>
print_r($_POST)return in your API script?