This module exports a constructor function which takes an options object.
Shopify(options)
Creates a new Shopify instance.
Arguments
options - Required - A plain JavaScript object that contains the
configuration options.
Options
shopName - Required - A string that specifies the shop name. The shop's
"myshopify.com" domain is also accepted.
apiKey - Required for private apps - A
string that specifies the API key of the app. This option must be used in
conjunction with the password option and is mutually exclusive with the
accessToken option.
password - Required for private apps - A
string that specifies the private app password. This option must be used in
conjunction with the apiKey option and is mutually exclusive with the
accessToken option.
accessToken - Required for public apps - A string representing the permanent
OAuth 2.0 access token. This option is mutually exclusive with the
apiKey and password options. If you are looking for a premade solution to
obtain an access token, take a look at the shopify-token module.
apiVersion - Optional - A string to specify the Shopify API
version to use for requests. Defaults to the oldest supported
stable version.
autoLimit - Optional - This option allows you to regulate the request rate
in order to avoid hitting the rate limit. Requests are
limited using the token bucket algorithm. Accepted values are a boolean or a
plain JavaScript object. When using an object, the calls property and the
interval property specify the refill rate and the bucketSize property the
bucket size. For example { calls: 2, interval: 1000, bucketSize: 35 }
specifies a limit of 2 requests per second with a burst of 35 requests. When
set to true requests are limited as specified in the above example. Defaults
to false.
parseJson - Optional - The function used to parse JSON. The function is
passed a single argument. This option allows the use of a custom JSON parser
that might be needed to properly handle long integer IDs. Defaults to
JSON.parse().
presentmentPrices - Optional - Whether to include the header to pull
presentment prices for products. Defaults to false.
stringifyJson - Optional - The function used to serialize to JSON. The
function is passed a single argument. This option allows the use of a custom
JSON serializer that might be needed to properly handle long integer IDs.
Defaults to JSON.stringify().
timeout - Optional - The number of milliseconds before the request times
out. If the request takes longer than timeout, it will be aborted. Defaults
to 60000, or 1 minute.
Return value
A Shopify instance.
Exceptions
Throws an Error exception if the required options are missing.
The callLimits property allows you to monitor the API call limit. The value is
an object like this:
{remaining: 30,current: 10,max: 40}
Values start at undefined and are updated every time a request is made. After
every update the callLimits event is emitted with the updated limits as
argument.
The Shopify API requires that you send a valid JSON string in the request body
including the name of the resource. For example, the request body to create a
country should be:
{
"country": {
"code": "FR",
"tax": 0.25
}
}
When using shopify-api-node you don't have to specify the full object but only
the nested one as the module automatically wraps the provided data. Using the
above example this translates to:
Shopify allows for adding metafields to various resources. You can use the
owner_resource and owner_id properties to work with metafields that belong
to a particular resource as shown in the examples below.
Each set of results may have the nextPageParameters and
previousPageParameters properties. These properties specify respectively the
parameters needed to fetch the next and previous page of results.
This feature is only available on version 2.24.0 and above.
请发表评论