php - Square API Create Item working code now returning an error -
after creating 1000 inventory items code, square started returning error.
the error returned was:
{"type":"bad_request","message":"'name' required"}
example code:
$postdata = array( 'id' => 'test_1433281486', 'name' => 'test', 'description' => 'test', 'variations' => array( 'id' => 'test_v1433281486', 'name' => 'regular', 'price_money' => array( 'currency_code' => 'usd', 'amount' => '19800', ), ), ); $json = json_encode($postdata); $curl = curl_init(); curl_setopt($curl, curlopt_httpheader, array( 'authorization: bearer ' . $access_token, 'content-type: application/json', 'accept: application/json')); curl_setopt($curl, curlopt_url, "https://connect.squareup.com/v1/me/items"); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_ssl_verifypeer, false); curl_setopt($curl, curlopt_ssl_verifyhost, false); curl_setopt($curl, curlinfo_header_out, true); curl_setopt($curl, curlopt_verbose, true); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, $json); $json = curl_exec($curl); curl_close($curl);
here json_encoded string:
{ "id":"test_1433281486", "name":"test", "description":"test", "variations": { "id":"test_v1433281486", "name":"regular", "price_money": { "currency_code":"usd", "amount":"19800" } } }
i have tried know simple create item code now, no longer works. returns message "name" required. code update images, fees, categories etc still works - can't create.
i still have 100's of new inventory items add, getting work imperative business.
variations needs passed in array. here how json should look:
{ "id":"test_1433281486", "name":"test", "description":"test", "variations": [{ "id":"test_v1433281486", "name":"regular", "price_money": { "currency_code":"usd", "amount":"19800" } }] }
thanks report! update our error messaging send proper message if variations not passed in array.
Comments
Post a Comment