Hi,
I have changed the code, it looks like I need to pass http_errors to stop guzzle catching the 500 to early.
<?php
require_once __DIR__ . '/vendor' . '/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new GuzzleHttp\Client();
function getSignature($requestContent = '')
{
$secureKey = pack('H*', file_get_contents("api-local.key"));
return hash_hmac('sha1', $requestContent, $secureKey);
}
//build request body and send
$headers = ['Authorization' => 'Token 7B3252C02EBDAEF0251B2BF2B'];
$json = '{
"ref": "55",
"label": "tedt",
"locale": "en_US",
"title": "product create from api",
"description": "product description from api",
"default_category": 5,
"visible": 1,
"price": 10.00,
"currency": 3,
"tax_rule": 3,
"weight": 10,
"brand_id": 0,
"lang": 2,
"virtual": 0,
"weight": 5.00,
"tax_price": 10.00
}
';
$post = (json_decode($json, true));
$post['sign'] = getSignature();
try {
$response = $client->request('POST', 'http://local.feedmark2/api/products', array('headers' => $headers, 'query' => $post, 'http_errors' => false));
$body = $response->getBody();
echo $body;
} catch (GuzzleHttp\Exception\BadResponseException $e) {
echo $e->getMessage();
$data = $response->json();
echo gettype($data);
}
?>
The response is failing on validation, I am not sure why as I'm adding required fields.
{"error":"Missing or invalid data: [Product reference *] , [Product title] , [Default product category *] , [locale] , [This product is online] , [This product does not have a physical presence] , [Product base price excluding taxes *] , [Product base price with taxes] , [Price currency *] , [Tax rule for this product *] , [Weight] , [Brand \/ Supplier] , [Summary] , [Detailed description] , [Conclusion] , [success_url] , [error_url] , [error_message]"}