I can get everything working and can put to contacts etc - but cannot put to Bills.
I have read and gone over everything but cant see any issues.
I am using the OAuth2 method (adoy/PHP-OAuth2)
I get the following response returned:
Array
(
[result] => You are being redirected.
[code] => 302
[content_type] => text/html; charset=utf-8
)
…but if I vary the code to insert a record to contacts rather than a bill it all works, so am thinking something in the PUT bills is broken.
Here is my code; appreciate anyone that knows the answer.
/// ++++++++++++++++++++++++++++++++++++++++++
/// DATA to POST
/// ++++++++++++++++++++++++++++++++++++++++++
//create array
$putData =
array ('bills' =>
array (
"contact" => "https://api.freeagent.com/v2/contacts/5040955",
"category" => "https://api.freeagent.com/v2/categories/285",
"reference" => "test reference",
"dated_on" => "2017-08-10",
"due_on" => "2017-08-10",
"total_value" => "1000.00",
"paid_value" => "80.0",
"due_value" => "20.0",
"sales_tax_value" => "-16.67",
"sales_tax_rate" => "20.0",
"status" => "Open",
"rebill_type" => "price",
"rebill_factor" => "20",
"rebill_to_project" => "https://api.freeagent.com/v2/projects/1",
"rebilled_on_invoice_item" => "https://api.freeagent.com/v2/invoices/1",
"updated_at" =>"2017-08-10T16:00:41Z",
"created_at" =>"2017-08-10T16:00:41Z",
/*"attachment" => array (
"url" => "https://api.freeagent.com/v2/attachments/3",
"content_src" =>"https://s3.amazonaws.com/freeagent-dev/attachments/1/original.pngAWSAccessKeyId=1K3MW21E6T8KWBY84B02&Expires=1314281186&Signature=GFAKDo%2Bi%2FsUMTYEgg6ZWGysB4k4%3D",
"content_type" => "image/png",
"file_name" => "barcode.png",
"file_size" => 7673
)*/
));
//Encode the array into JSON.
//$jsonDataEncoded = json_encode($jsonData);
$jsonDataEncoded = json_encode($putData);
echo $jsonDataEncoded;
//when we have a token, just set up the client
$client->setAccessToken($_GET['token']);
$client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
//and make the request to the API
$response = $client->fetch(
$base_url . '/bills', //API path
//array($putData), //request parameters
//array($jsonDataEncoded), //request parameters
//$putData,
$jsonDataEncoded,
OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST, DELETE ...PUT means to update
array('User-Agent' => 'Smart Inventory', 'Accept' => 'application/json','Content-Type' => 'application/json') //API requires UA header
);
//show response
echo '<pre>'.print_r($response, true).'</pre>';