PHP Rest API post request using Linnworks API -


i new rest apis , trying started using linnworks api our order management software. starting point trying use post request current stock level of 1 item using it's guid.

the documentation request can seen here:

http://apidoc.linnworks.net/home/apimethod/getstocklevel

i have gone through first stages of post requests using userid , password issued token explained here:

http://apidoc.linnworks.net/home/page/auth%20introduction

i have tried create post request using stream_context_create , information lot of blog posts have been reading. have written following code keep getting blank screen not warning or error message. can see going wrong? new may missing major. have omitted token security purposes:

<?php  $postdata = array(     'stockitemid' => 'bb0ef47f-f3fe-47b4-8863-ddfe8bc69b29'     );  $opts = array('http' =>     array(         'method' => 'post',         'protocol_version' => 1.1,         'header' =>                      'authorization: token my-token-here\r\n'.                     'host: eu1.linnworks.net\r\n'.                     'content-type: application/x-www-form-urlencoded\r\n'.                     'accept-language: en\r\n',         'content' => $postdata         )     );  $context = stream_context_create($opts);  $result = file_get_contents('https://eu1.linnworks.net//api/stock/getstocklevel',false, $context);  echo $result; ?> 

when doing var_dump of each variable following if helps:

var dump: $postdata

array(1) { ["stockitemid"]=> string(36) "bb0ef47f-f3fe-47b4-8863-ddfe8bc69b29" }  

var dump: $opts

array(1) { ["http"]=> array(4) { ["method"]=> string(4) "post" ["protocol_version"]=> float(1.1) ["header"]=> string(162) "authorization: token my-token-here\r\nhost: eu1.linnworks.net\r\ncontent-type: application/x-www-form-urlencoded\r\naccept-language: en\r\n" ["content"]=> array(1) { ["stockitemid"]=> string(36) "bb0ef47f-f3fe-47b4-8863-ddfe8bc69b29" } } }  

var dump: $context

resource(2) of type (stream-context)  

var dump: $result

bool(false) 

any appreciated

i have started developing linnworks , there docs unhelpful least.

however, there 2 important things note experience. one, authorisationbyapplication have use different server return valid token:

https://api.linnworks.net/api/auth/authorizebyapplication

and request application authorised account. here function accounts categories:

$paras = array( 'token' => $u->token );  getlinn('inventory/getcategories', $paras);  function getlinn($method, $paras) { $url = 'https://eu1.linnworks.net/api/' . $method; $ahttp = array(     'http' => array(         'method' => 'post',         'content' => '',         'header' => ["authorization: " . $paras['token'],             "transfer-encoding: chunked",             "content-encoding: chunked",             "content-type: application/x-www-form-urlencoded"         ]     ) ); //print_r($ahttp); $context = stream_context_create($ahttp); $contents = file_get_contents($url, false, $context);  return $contents; } 

hope may in future :)


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -