Tuesday 15 March 2011

php - Square-Connect Inventory Update cURL Call -



php - Square-Connect Inventory Update cURL Call -

i trying update square inventory inventory database website , maintain getting error.

response:{"type":"bad_request","message":"missing required parameter `quantity_delta`"}

i adding quantity_delta field , adjustment_type curl phone call because documentation says, there 3 options in documentation , 1 of them has (optional) next using 2 appear required. can't capture post body see how phone call going out, maybe type or json_encode issue, debugging giving me issue.

i writing headers , response text file fore easy reading.

here code:

$i = $_get['id']; $n = $_get['name']; $q = $_get['qty']; $s = $_get['sku']; $c = $_get['current']; $sync = $_get['sync']; if($c > $q){ $up = $q - $c; $reason = "sale"; }else{ $up = $c + $q; $reason = "receive_stock"; } $postdata = array( "quantity_delta" => $up, "adjustment_type" => $reason); $b = json_encode($postdata); $fp = fopen('curlout.txt', 'rw+'); fopen('curlout.txt', 'rw+'); $curl = curl_init(); curl_setopt($curl, curlopt_httpheader, array('authorization: bearer *****_******' )); curl_setopt($curl, curlopt_url, "https://connect.squareup.com/v1/me/inventory/".$i.""); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, $b); curl_setopt($curl, curlopt_returntransfer, 1); 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, 1); curl_setopt($curl, curlopt_stderr, $fp); if(!curl_exec($curl)){ die('error: "' . curl_error($curl) . '" - code: ' . curl_errno($curl)); } $filename = 'curlout.txt'; if (is_writable($filename)){ echo 'the file writeable'; }else{ echo 'nope'; } $ch = curl_exec ($curl); $sentcall = curl_getinfo($curl, curlinfo_header_out); $dump = fopen("curlout.txt","a") or die("unable open file!"); $dumptxt = "header info:".$sentcall . "response:".$ch."\n\n"; fwrite($dump,$dumptxt); curl_close ($curl); fclose('curlout.txt'); var_dump(json_decode($ch,true));

can please tell me doing wrong? have been trying days figure out wrong curl call. can curl calls read info square-connect api no issues. have repetitive code in here display output/response in different ways hoping more information. post header info using culinfo_header_out.

header info:post /v1/me/inventory/011a799a-****-****-****-4f5b70dc1494 http/1.1 host: connect.squareup.com accept: */* authorization: bearer *****_***** content-length: 47 content-type: application/x-www-form-urlencoded

thank you.

i believe error occurring because request's content-type header application/x-www-form-urlencoded. requests connect api must have content-type of application/json match request body.

this unhelpful error message receive in case; work api engineering science team improve it.

php curl square-connect

No comments:

Post a Comment