App reviews, troubleshooting, and recommendations
Hi,
How to increase the lifetime of the customerAccessToken expiresAt? I can't find any documentation to increate the lifetime of the customer access token.
Thank You
See if this works for you.
In Shopify, the CustomerAccessToken
is a token that is generated when a customer logs in or creates an account on your store. This token is used to authenticate the customer's requests to your store's API.
The lifetime of a CustomerAccessToken
is determined by the expires_at
field in the token's metadata. By default, the lifetime of a CustomerAccessToken
is 1 hour (3600 seconds).
To increase the lifetime of a CustomerAccessToken
in Shopify, you can follow these steps:
Retrieve the CustomerAccessToken
that you want to modify by making a request to the Shopify API.
Determine the new expires_at
time that you want to set for the token. This can be any valid timestamp in the future.
Update the expires_at
field in the CustomerAccessToken
metadata with the new timestamp.
Save the updated CustomerAccessToken
to the Shopify API using a PUT
request.
Here's an example of how to update the CustomerAccessToken
expiration time in Shopify using the Shopify API and the Shopify API client for Node.js:
const Shopify = require('shopify-api-node');
// Initialize the Shopify API client
const shopify = new Shopify({
shopName: 'your-shop-name',
accessToken: 'your-access-token'
});
// Retrieve the CustomerAccessToken
const customerAccessToken = await shopify.customerAccessToken.get(customerAccessTokenId);
// Set the new expiration time
const newExpiresAt = new Date(Date.now() + 7200 * 1000); // 2 hours from now
// Update the CustomerAccessToken
customerAccessToken.expires_at = newExpiresAt.toISOString();
await shopify.customerAccessToken.update(customerAccessTokenId, customerAccessToken);
In this example, we first retrieve the CustomerAccessToken
using its ID. We then set the new expiration time to 2 hours from the current time. Finally, we update the CustomerAccessToken
in Shopify using the updated metadata.
Thank you , Let me try it out
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023