Solved

Beginner question: Rest API GET request with shopify-php-api always has empty response body

acribis
Shopify Partner
5 1 3

Hi there! 

 

I'm quite a beginner with Shopify app development. I'm trying to develop a simple app and I need to use offline mode, as the app will handle some webhook events in the future. 

 

My issue is that every REST api call results in an empty body and I have absolutely no clue why. Here is my test code:

 

Route::get('/test', function () {

$shop = '<hidden>.myshopify.com'; //shop name hidden in forum post for security reasons

$session = Utils::loadOfflineSession($shop);
$client = new Rest($session->getShop(), $session->getAccessToken());
$result = $client->get('products', [], ['limit' => 5]);

return $result->getBody();

});

The result is always the following:

 

 

GuzzleHttp\Psr7\Stream::__set_state(array(
   'stream' => NULL,
   'size' => NULL,
   'seekable' => true,
   'readable' => true,
   'writable' => true,
   'uri' => 'php://temp',
   'customMetadata' => 
  array (
  ),
))

 

 

 Probably I'm doing something wrong - but I have no clue what. Is anybody out there how can help me?

 

Best, Mischa

Accepted Solution (1)

acribis
Shopify Partner
5 1 3

This is an accepted solution.

I was meanwhile able to solve it. I need to access 

$result->getBody()->getContents();

to get the content of the response. Thanks. 

View solution in original post

Replies 3 (3)

PromarkDC10
Tourist
9 0 0
Refer to Shopify's OA Documentation
Darel M McDonald Sr
acribis
Shopify Partner
5 1 3

Hi! Do you mean the OAuth documentation? I was reading the the OAuth and REST documentation already. The example I used for testing comes from the shopify-php-api documentation. The example listed there was:

 

use Shopify\Clients\Rest;

$client = new Rest($session->getShop(), $session->getAccessToken());
$response = $client->get('products');

 

The difference to my example is that I use offline mode. No matter what REST request I do, I always receive a 200 response but with an empty body. 

acribis
Shopify Partner
5 1 3

This is an accepted solution.

I was meanwhile able to solve it. I need to access 

$result->getBody()->getContents();

to get the content of the response. Thanks.