Offline access token expired 401

Offline access token expired 401

RokasVaitkevici
Shopify Partner
2 0 2

Hi, I wanted to get shop access token, so I could do data sync while they're out of session, but when I try to do that I get 401, although I use offline access token taken from sessions table.

 

Strange thing is that it happens not for all shops, but to some. Another anomaly is that broken shop webhook, but only one, started throwing 401s as well until it got removed.


This is basic script that I use to get access token it:

const apiKey = "...";
const sharedSecret = "...";
const refreshToken = "...";

const accessToken = "..."; // from session table with no expiration, marked offline
const shop = "....myshopify.com";

const postData = {
  client_id: apiKey,
  client_secret: sharedSecret,
  refresh_token: refreshToken,
  access_token: accessToken,
};

(async () => {
  const response = await fetch(
    `https://${shop}/admin/oauth/access_token.json`,
    {
      method: "post",
      body: JSON.stringify(postData),
      headers: { "Content-Type": "application/json" },
    },
  );
  console.log(response);
  // The response includes the updated access token for future requests.
  const data = await response.json();
  accessToken = data["access_token"];
  console.log(accessToken);
})();

Just to make it clear as well, that shop is still active in my app, it just haven't logged in for quite a while, but my assumption is that it doesn't matter, because offline token, shouldn't expire, so why did it?

 

Any help would be highly appreciated.

Replies 0 (0)