How to increase the lifetime of the customerAccessToken expiresAt

How to increase the lifetime of the customerAccessToken expiresAt

rdewan
Shopify Partner
4 0 0

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.

 

Screenshot 2566-04-19 at 5.33.12 PM.png

Thank You

Replies 2 (2)

magecomp
Shopify Partner
461 31 47

 

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:

  1. Retrieve the CustomerAccessToken that you want to modify by making a request to the Shopify API.

  2. Determine the new expires_at time that you want to set for the token. This can be any valid timestamp in the future.

  3. Update the expires_at field in the CustomerAccessToken metadata with the new timestamp.

  4. 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.

 
Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website
rdewan
Shopify Partner
4 0 0

Thank you , Let me try it out