Post

Replies

Boosts

Views

Activity

Reply to Connect Store Server API always return 401
Hello! I hope you are doing well. If you haven't already fixed the issue, I wanted to share with you that this worked for me. const getAppFromAppleStoreConnect = async(callback)=>{ const { homedir } = await import ('node:os'); const privateKey = fs.readFileSync(`${homedir()}/.appstoreconnect/private_keys/AuthKey_${process.env.APPLESTORE_KEY}.p8`, 'utf8'); const issuerId = process.env.APPLEISSUEID; const now = moment().utc(); const header = { "alg": "ES256", "kid": process.env.APPLESTORE_KEY, "typ": "JWT" } const payload = { "iss":issuerId, "iat": now.unix(), "exp": now.add(20, 'minutes').unix(), "aud": "appstoreconnect-v1", } const gen_jwt = jwt.sign(payload, privateKey, { algorithm: "ES256", header, }); let dataToSend; async.series( [ (cb) => { let options = { method: "GET", url: "https://api.appstoreconnect.apple.com/v1/apps", headers: { Authorization: `Bearer ${gen_jwt}`, }, json:true }; request(options, (err, response, body) => { if (err) { console.log(err); cb(err); } else { dataToSend = body; cb(); } }); }, ], (err) => { if (err) callback(err); else { callback(null, dataToSend); } } ); };
Apr ’23