A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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
Solved! Go to the solution
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.
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.
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.