4

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 Answer 1

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 ?

2
  • Even if token is changed Response is 500
    – blakcaps
    Jul 14, 2016 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, 2016 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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