You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The domain of the store. It can be the Shopify myshopify.com domain or a custom store domain.
apiVersion
string
The requested Storefront API version
publicAccessToken?
string
Storefront API public access token. Either publicAccessToken or privateAccessToken must be provided at initialization.
privateAccessToken?
string
Storefront API private access token. Either publicAccessToken or privateAccessToken must be provided at initialization. Important: Storefront API private delegate access tokens should only be used in a server-to-server implementation.
clientName?
string
Name of the client
retries?
number
The number of HTTP request retries if the request was abandoned or the server responded with a Too Many Requests (429) or Service Unavailable (503) response. Default value is 0. Maximum value is 3.
Returns Storefront API specific headers needed to interact with the API. If customHeaders is provided, the custom headers will be included in the returned headers object.
getApiUrl
(apiVersion?: string) => string
Returns the shop specific API url. If an API version is provided, the returned URL will include the provided version, else the URL will include the API version set at client initialization.
Requests data from Storefront API using the provided GQL operation string and ApiClientRequestOptions object and returns a normalized response object.
StorefrontApiClientConfig properties
Name
Type
Description
storeDomain
string
The secure store domain
apiVersion
string
The Storefront API version to use in the API request
publicAccessToken
string | null
The provided public access token
privateAccessToken
string | null
The provided private access token
headers
{[key: string]: string}
The headers generated by the client during initialization
apiUrl
string
The API URL generated from the provided store domain and api version
clientName?
string
The provided client name
retries?
number
The number of retries the client will attempt when the API responds with a Too Many Requests (429) or Service Unavailable (503) response
ApiClientRequestOptions properties
Name
Type
Description
variables?
Record<string, any>
Variable values needed in the graphQL operation
apiVersion?
string
The Storefront API version to use in the API request
customHeaders?
Record<string, string>
Customized headers to be included in the API request
retries?
number
Alternative number of retries for the request. Retries only occur for requests that were abandoned or if the server responds with a Too Many Request (429) or Service Unavailable (503) response. Minimum value is 0 and maximum value is 3.
ClientResponse<TData>
Name
Type
Description
data?
TData | any
Data returned from the Storefront API. If TData was provided to the function, the return type is TData, else it returns type any.
Errors object that contains any API or network errors that occured while fetching the data from the API. It does not include any UserErrors.
extensions?
{[key: string]: any}
Additional information on the GraphQL response data and context. It can include the context object that contains the context settings used to generate the returned API response.
constshopQuery=` query shop { shop { name id } }`;const{data, errors, extensions}=awaitclient.request(shopQuery);
Dynamically set the Storefront API version per request
constproductQuery=` query ProductQuery($handle: String) { product(handle: $handle) { id title handle } }`;const{data, errors, extensions}=awaitclient.request(productQuery,{variables: {handle: 'sample-product',},apiVersion: '2023-07',});
Add custom headers to API request
constproductQuery=` query ProductQuery($handle: String) { product(handle: $handle) { id title handle } }`;const{data, errors, extensions}=awaitclient.request(productQuery,{variables: {handle: 'sample-product',},customHeaders: {'Shopify-Storefront-Id': 'shop-id',},});
Dynamically set the number of retries per request
constproductQuery=` query ProductQuery($handle: String) { product(handle: $handle) { id title handle } }`;const{data, errors, extensions}=awaitclient.request(productQuery,{variables: {handle: 'sample-product',},retries: 2,});
Provide GQL query type to client.request()
import{print}from'graphql/language';// GQL operation types are usually auto generated during the application buildimport{CollectionQuery}from'types/appTypes';importcollectionQueryfrom'./collectionQuery.graphql';const{data, error, extensions}=awaitclient.request<CollectionQuery>(print(collectionQuery),{variables: {handle: 'sample-collection',},});
Using client.fetch() to get API data
constshopQuery=` query shop { shop { name id } }`;constresponse=awaitclient.fetch(shopQuery);if(response.ok){const{errors, data, extensions}=awaitresponse.json();}
Log Content Types
UnsupportedApiVersionLog
This log content is sent to the logger whenever an unsupported API version is provided to the client.
Property
Type
Description
type
LogType['UNSUPPORTED_API_VERSION']
The type of log content. Is always set to UNSUPPORTED_API_VERSION
Contextual data regarding the upcoming retry attempt.
requestParams: parameters used in the request lastResponse: previous response retryAttempt: the current retry attempt count maxRetries: the maximum number of retries