3

I am trying to call external api from Magento. Below is the request,

$client = $this->_httpClientFactory->create();
$client->setUri('thirdpartyurl.com/api/');
$client->setMethod(\Zend_Http_Client::PUT);
$client->setHeaders(\Zend_Http_Client::CONTENT_TYPE, 'application/json');
$client->setHeaders('Accept','application/json');
$client->setHeaders("Authorization","Bearer 1212121212121");
$client->setParameterPost($params); //json
$response= $client->request();


return $response->getBody();

Always response comes as

Unable to read response, or response is empty

Any help would be appreciated.

1

Since you are sending a PUT request I would expect a 200 request (for most REST APIs) to return NULL so it would behave as expected, did you try changing the token to see if a 400 is returning a response body ?

  • Even if token is changed Response is 500 – blakcaps Jul 14 '16 at 11:04
  • 4
    Well by looking at your code I can see that the headers might be wrong so try setHeaders ( array ( "accept: application/json", "authorization: ".$apikey, "content-type: application/json", ) ); , then again I am using now magento 1.9 and curl for my API call but does Zend_Http_Client support PUT ? I would try cURL just to see if it works for your code – Dan Jul 14 '16 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.