FROM CACHE - en_header

Uncaught Error: Call to a member function client() - Shopify API

Danielnz
Excursionist
29 0 10

I'm trying to send a request to Shopify with fulfillment details on an order (i.e. telling the API that an order is fulfilled and what hte tracking details are.)

I'm using the example code from the Dev API docs, as follows:

<?php

use Shopify\Clients\Rest; $accessToken = "xxxxxx";
$client = new Rest("xxx.myshopify.com", $accessToken);
$response = $client->post(
  "fulfillments", [ "fulfillment" => [ "message" => "The package was shipped this morning.", "notify_customer" => false, "tracking_info" => [ "number" => 1562678, "url" => "https://www.my-shipping-company.com", "company" => "my-shipping-company" ], "line_items_by_fulfillment_order" => [ "fulfillment_order_id" => 4065174126789, "fulfillment_order_line_items" => [ "id" => 6695635255493, "quantity" => 1 ] ] ] ] );

When I run my script the following error is reported:

[08-Oct-2021 19:54:54 UTC] PHP Fatal error:  Uncaught Error: Call to a member function client() on null in /home/.../vendor/shopify/shopify-api/src/Clients/Http.php:164

Stack trace:
#0 /home/.../vendor/shopify/shopify-api/src/Clients/Rest.php(48): Shopify\Clients\Http->request('admin/api//fulf...', 'POST', Array, Array, Array, NULL, 'application/jso...')
#1 /home/.../vendor/shopify/shopify-api/src/Clients/Http.php(74): Shopify\Clients\Rest->request('fulfillments', 'POST', Array, Array, Array, NULL, 'application/jso...')
#2 /home/.../app2/test.php(14): Shopify\Clients\Http->post('fulfillments', Array)
#3 {main} thrown in /home/.../vendor/shopify/shopify-api/src/Clients/Http.php on line 164
Replies 5 (5)
rcgang
New Member
1 0 0

use Shopify\Clients\Rest;
use Shopify\Auth\FileSessionStorage;

Shopify\Context::initialize('apiKey', 'apiSecretKey', 'scopes', 'hostName.myshopify.com', new FileSessionStorage('/tmp/php_sessions'), '2021-10');

$client = new Rest('xxx.myshopify.com', 'access_token');
$response = $client->get(
"orders", [
"created_at_min" => "2021-11-01T00:00:00+09:00"
]
);

Let me know if it worked. 
Thank you

 

 

AlessandroGn
New Member
16 0 0

But i have only one api key.

 

Where do I find "apiSecretKey" ?

 

Thanks

Magento developer, Shopify developer, Woocommerce Developer
Weeknd
New Member
1 0 0

Hello.

 

You can take your apiSecretKey from application settings. 

a10011001
Shopify Partner
2 0 0

object(Shopify\Clients\RestResponse)#21 (8) { ["pageInfo":"Shopify\Clients\RestResponse":private]=> NULL ["requestId":"Shopify\Clients\HttpResponse":private]=> string(36) "XXXXXXXXXXX-42b3-8315-21fa5e74c17a" ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=> string(2) "OK" ["statusCode":"GuzzleHttp\Psr7\Response":private]=> int(200) ["headers":"GuzzleHttp\Psr7\Response":private]=> array(31) { ["Date"]=> array(1) { [0]=> string(29) "Wed, 30 Mar 2022 09:28:57 GMT" } ["Content-Type"]=> array(1) { [0]=> string(31) "application/json; charset=utf-8" } ["Transfer-Encoding"]=> array(1) { [0]=> string(7) "chunked" } ["Connection"]=> array(1) { [0]=> string(10) "keep-alive" } ["X-Sorting-Hat-PodId"]=> array(1) { [0]=> string(2) "60" } ["X-Sorting-Hat-ShopId"]=> array(1) { [0]=> string(11) "565268XXXXX" } ["Vary"]=> array(1) { [0]=> string(15) "Accept-Encoding" } ["Referrer-Policy"]=> array(1) { [0]=> string(24) "origin-when-cross-origin" } ["X-Frame-Options"]=> array(1) { [0]=> string(4) "DENY" } ["X-ShopId"]=> array(1) { [0]=> string(11) "565268XXXXX" } ["X-ShardId"]=> array(1) { [0]=> string(2) "60" } ["X-Stats-UserId"]=> array(1) { [0]=> string(0) "" } ["X-Stats-ApiClientId"]=> array(1) { [0]=> string(7) "6XXXXXX" } ["X-Stats-ApiPermissionId"]=> array(1) { [0]=> string(12) "XXXXXXX" } ["HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT"]=> array(1) { [0]=> string(4) "1/40" } ["X-Shopify-Shop-Api-Call-Limit"]=> array(1) { [0]=> string(4) "1/40" } ["X-Shopify-API-Version"]=> array(1) { [0]=> string(7) "2021-10" } ["Strict-Transport-Security"]=> array(1) { [0]=> string(15) "max-age=XXXXXX" } ["X-Shopify-Stage"]=> array(1) { [0]=> string(10) "production" } ["Content-Security-Policy"]=> array(1) { [0]=> string(845) "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://checkout.shopifycs.com https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=show&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=61a2927a-7ad1-42b3-8315-21fa5e74c17a" } ["X-Content-Type-Options"]=> array(1) { [0]=> string(7) "nosniff" } ["X-Download-Options"]=> array(1) { [0]=> string(6) "noopen" } ["X-Permitted-Cross-Domain-Policies"]=> array(1) { [0]=> string(4) "none" } ["X-XSS-Protection"]=> array(1) { [0]=> string(205) "1; mode=block; report=/xss-report?source%5Baction%5D=show&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=61a2927a-7ad1-42b3-8315-21fa5e74c17a" } ["X-Dc"]=> array(1) { [0]=> string(45) "gcp-asia-northeast1,gcp-us-east1,gcp-us-east1" } ["X-Request-ID"]=> array(1) { [0]=> string(36) "XXXXXXXXXX42b3-8315-21fa5e74c17a" } ["CF-Cache-Status"]=> array(1) { [0]=> string(7) "DYNAMIC" } ["Expect-CT"]=> array(1) { [0]=> string(87) "max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"" } ["Server"]=> array(1) { [0]=> string(10) "cloudflare" } ["CF-RAY"]=> array(1) { [0]=> string(20) "6f3fXXXXXXX0807e-NRT" } ["alt-svc"]=> array(1) { [0]=> string(43) "h3=":443"; ma=86400, h3-29=":443"; ma=86400" } } ["headerNames":"GuzzleHttp\Psr7\Response":private]=> array(31) { ["date"]=> string(4) "Date" ["content-type"]=> string(12) "Content-Type" ["transfer-encoding"]=> string(17) "Transfer-Encoding" ["connection"]=> string(10) "Connection" ["x-sorting-hat-podid"]=> string(19) "X-Sorting-Hat-PodId" ["x-sorting-hat-shopid"]=> string(20) "X-Sorting-Hat-ShopId" ["vary"]=> string(4) "Vary" ["referrer-policy"]=> string(15) "Referrer-Policy" ["x-frame-options"]=> string(15) "X-Frame-Options" ["x-shopid"]=> string(8) "X-ShopId" ["x-shardid"]=> string(9) "X-ShardId" ["x-stats-userid"]=> string(14) "X-Stats-UserId" ["x-stats-apiclientid"]=> string(19) "X-Stats-ApiClientId" ["x-stats-apipermissionid"]=> string(23) "X-Stats-ApiPermissionId" ["http_x_shopify_shop_api_call_limit"]=> string(34) "HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT" ["x-shopify-shop-api-call-limit"]=> string(29) "X-Shopify-Shop-Api-Call-Limit" ["x-shopify-api-version"]=> string(21) "X-Shopify-API-Version" ["strict-transport-security"]=> string(25) "Strict-Transport-Security" ["x-shopify-stage"]=> string(15) "X-Shopify-Stage" ["content-security-policy"]=> string(23) "Content-Security-Policy" ["x-content-type-options"]=> string(22) "X-Content-Type-Options" ["x-download-options"]=> string(18) "X-Download-Options" ["x-permitted-cross-domain-policies"]=> string(33) "X-Permitted-Cross-Domain-Policies" ["x-xss-protection"]=> string(16) "X-XSS-Protection" ["x-dc"]=> string(4) "X-Dc" ["x-request-id"]=> string(12) "X-Request-ID" ["cf-cache-status"]=> string(15) "CF-Cache-Status" ["expect-ct"]=> string(9) "Expect-CT" ["server"]=> string(6) "Server" ["cf-ray"]=> string(6) "CF-RAY" ["alt-svc"]=> string(7) "alt-svc" } ["protocol":"GuzzleHttp\Psr7\Response":private]=> string(3) "1.1" ["stream":"GuzzleHttp\Psr7\Response":private]=> object(GuzzleHttp\Psr7\Stream)#28 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private]=> resource(4) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private]=> NULL ["seekable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private]=> string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=> array(0) { } } }

a10011001
Shopify Partner
2 0 0

use Shopify\Clients\Rest;
use Shopify\Auth\FileSessionStorage;

Shopify\Context::initialize('apiKey', 'apiSecretKey', 'scopes', 'hostName.myshopify.com', new FileSessionStorage('/tmp/php_sessions'), '2021-10');

$client = new Rest('xxx.myshopify.com', 'access_token');
$response = $client->get( "products/6750957699133");

);