JanHalozan / iTunesConnectAnalytics

NodeJS package for iTunes Connect app analytics API
Other
143 stars 44 forks source link

StatusCodeError: 412 #53

Open doguh opened 3 years ago

doguh commented 3 years ago

Connecting to iTunes Connect now results in a 412 error.

    const i = new itc.Itunes(
      config.appstore.login,
      config.appstore.password,
      {
        errorCallback: reject,
        successCallback: () => resolve(i),
      }
    );

Will reject with StatusCodeError: 412 - {"authType":"sa"} error.

See the PR below for a possible fix: https://github.com/JanHalozan/iTunesConnectAnalytics/pull/52

sann05 commented 3 years ago

@doguh you are my hero

sann05 commented 3 years ago

It seems like it's not over yet:

var itc = require('itunesconnectanalytics');
var Itunes = itc.Itunes;

var username = 'myname';
var password = 'mypass';
var appId = '12345'; //My apple id

var instance = new Itunes(username, password, {
  errorCallback: function(e) {
    console.log('Error logging in: ' + e);
  },
  successCallback: function(d) {
    console.log('Logged in');
  }
});
instance.getApps(function(error, data) {
  console.log(JSON.stringify(data, null, 2));
});

It returns:

Logged in
null
sann05 commented 3 years ago

It seems like it's not over yet:

var itc = require('itunesconnectanalytics');
var Itunes = itc.Itunes;

var username = 'myname';
var password = 'mypass';
var appId = '12345'; //My apple id

var instance = new Itunes(username, password, {
  errorCallback: function(e) {
    console.log('Error logging in: ' + e);
  },
  successCallback: function(d) {
    console.log('Logged in');
  }
});
instance.getApps(function(error, data) {
  console.log(JSON.stringify(data, null, 2));
});

It returns:

Logged in
null

It turns out that itunes analytics API URL was changed to https://appstoreconnect.apple.com/analytics/api/v1

doguh commented 3 years ago

Good catch @sann05!

I'll update my pull request

Reiszecke commented 3 years ago

@doguh sorry for the @ but you seem to be the only active contributor at this point. Do you have some info on https://github.com/JanHalozan/iTunesConnectAnalytics/issues/43 ? My best guess is that we are using it wrong but cookies aren't explained anywhere in the readme.

What does your implementation look like, do you override .getCookies somewhere in your app? Whatever I try, the session only survives for about 6 hours .__.

doguh commented 3 years ago

@Reiszecke I'm not using 2FA so I don't know about this issue.

That being said, the session expiring after 6 hours seems normal to me, it can't last forever.

In my implementation I create a new ict.Itunes(login, password, callback) at the start of every job (a job being pulling app analytics data for our apps for example). If your job lasts more than 6 hours, perhaps you'll need to create a new ict.Itunes object every 6 hours.

Reiszecke commented 3 years ago

How did you manage to make an account without 2FA tho? I would love to just do that tbh

doguh commented 3 years ago

@Reiszecke It's an relatively old account. I never activated 2FA on it. I don't think there is a way to disable it once it has been enabled :/

Reiszecke commented 3 years ago

Hey @doguh I found this fork which has it all apparently - https://github.com/JanHalozan/iTunesConnectAnalytics/issues/43#issuecomment-910428325

Just letting you know you may want to fetch/merge some commits into your repo too