Skip to content

Commit

Permalink
Shopify - REST API deprecation - Move to GraphQL endpoint (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstowey authored Nov 9, 2024
1 parent 2d3b296 commit 4ad60eb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Provider extends AbstractProvider
{
public const IDENTIFIER = 'SHOPIFY';

private const API_VERSION = '2024-10';

protected function getAuthUrl($state): string
{
return $this->buildAuthUrlFromBase($this->shopifyUrl('/admin/oauth/authorize'), $state);
Expand All @@ -25,14 +27,24 @@ protected function getTokenUrl(): string
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get($this->shopifyUrl('/admin/shop.json'), [
$response = $this->getHttpClient()->post($this->shopifyUrl('/admin/api/'.self::API_VERSION.'/graphql.json'), [
RequestOptions::HEADERS => [
'Accept' => 'application/json',
'X-Shopify-Access-Token' => $token,
],
RequestOptions::JSON => [
'query' => '{
shop {
id
email
myshopifyDomain
shopOwnerName
}
}'
]
]);

return json_decode((string) $response->getBody(), true)['shop'];
return json_decode($response->getBody(), true)['data']['shop'];
}

/**
Expand All @@ -42,8 +54,8 @@ protected function mapUserToObject(array $user)
{
return (new User)->setRaw($user)->map([
'id' => $user['id'],
'nickname' => $user['myshopify_domain'],
'name' => $user['name'],
'nickname' => $user['myshopifyDomain'],
'name' => $user['shopOwnerName'],
'email' => $user['email'],
'avatar' => null,
]);
Expand Down

0 comments on commit 4ad60eb

Please sign in to comment.