JWT invalid error when calling app store server api

Hi, This is first time posting in here.

Now our app is using In-app purchase and i'm implementing server logics using app-store-server-api.

But from yesterday, i'm facing 'http status code 401 Unauthorized error' when calling some apis.

I did many trials to fix this error and issue new key for api in app store connect. But I can't resolve this error. Even can't know what is the reason.

I attach my real code for calling 'get transaction info' api. Please give some help for me!!!!

const jwt = require('jsonwebtoken');
const fs = require('fs');
const axios = require('axios');

getApiJWTToken = () => {
        // header
        const keyId = process.env.APP_STORE_KEY_ID;
        const issuerId = process.env.APP_STORE_ISSUER_ID;
        const appBundleId = process.env.APP_BUNDLE_ID;

        const header = {
            alg: 'ES256',
            kid: keyId,
            typ: 'JWT',
        };

        // payload
        const issuedAt = Number(dayjs().unix());
        
        const payload = {
            iss: issuerId,
            iat: issuedAt,
            aud: 'appstoreconnect-v1',
            bid: appBundleId,
        };

        // sign
        const keyString = fs.readFileSync(filePath, 'utf-8');

        const token = jwt.sign(payload, keyString, {
            algorithm: 'ES256',
            header: header,
            expiresIn: '30m',
        });
        
        return btoa(token);
    };

requestSingleTransactionInfo = async ({ transactionId }) => {
        try {
            // jwt token
            const token = this.getApiJWTToken();

            const envType = process.env.APP_STORE_SERVER_API_ENV;

            const commonUrl = `/inApps/v1/transactions/${transactionId}`;
            let baseUrl;
            if (envType === 'Sandbox') {
                // sandbox
                baseUrl = 'https://api.storekit-sandbox.itunes.apple.com';
            } else if (envType === 'Production') {
                // production
                baseUrl = 'https://api.storekit.itunes.apple.com';
            }
            const url = `${baseUrl}${commonUrl}`;
            
const response = await axios.get(url, {
                headers: {
                    Authorization: `Bearer ${token}`,
                },
            });

            const { signedTransactionInfo } = response.data;

            const transactionInfo = await decodeTransaction(signedTransactionInfo);
            console.log(transactionInfo);
            return transactionInfo;
        } catch (err) {
            throw err;
        }
    };

And the situation is really strange. I am using same auth info in our production server and develop server. And the code implemented apple in-app purchases is exactly same.

But the problem is only issues in develop server. In develop server, we use sandbox environment for test.

AND NOW, everything is same in code but the error message and status code is different. 401 Unauthorized to 400 Invalid transaction id.

How can i resolve this problem?

For generating JWTs in Node.js, we recommend using the App Store Server Library (https://github.com/apple/app-store-server-library-node) which can generate the tokens and call the endpoints.

JWT invalid error when calling app store server api
 
 
Q