isaced / appstore-connect-sdk

A TypeScript module for Node.js that interacts with the App Store Connect API, providing support for all APIs based on OpenAPI specification.
MIT License
25 stars 7 forks source link

Unable to make requests due to token not being properly injected #21

Open toddgower-hiatus opened 5 months ago

toddgower-hiatus commented 5 months ago

I'm just getting started with the SDK and running into an issue getting my first request to succeed.

Here's my code:

export const getReleaseVersions = async (req, res) => {
    const { appStoreConnect } = config;
    const { privateKey, issuerId, keyId } = appStoreConnect;
    const client = new AppStoreConnectAPI({
        issuerId: issuerId,
        privateKeyId: keyId,
        privateKey: privateKey,
    });
    const api = await client.create(AppsApi);
    const result = await api.appsAppStoreVersionsGetToManyRelated({ id: 'xxxxxxxxx', limit: 10});
    const version = result.data[0].attributes.versionString;
    res.send({ version });
};

It fails when trying to make the appsAppStoreVersionsGetToManyRelated and throws an error: error: FetchError: The request failed and the interceptors did not return an alternative response

Digging into the code, it seems that the auth token isn't properly set in the http request headers here. this.configuration does not have an access token property. Instead it looks like this:

this.configuration:  Configuration {
  configuration: {
    headers: {
      Authorization: 'Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkhITjkyRDNOTTYiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiI2OWE2ZGU4My1jNGVlLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJhdWQiOiJhcHBzdG9yZWNvbm5lY3QtdjEiLCJleHAiOjE3MTQyNDM1NjMuMTZ9.jSmHuFrvBEefMKAcrSCF6xZWL2nvTOjRTgGUEj38EsE-kVfXBpbK0aN0y9-l7y23ifl2I-IsYr-jCnQRPhxpow'
    },
    fetchApi: undefined,
    basePath: undefined
  }
}

Did I do something incorrectly when I configured the API in the code?