Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new iTunes login #52

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ instance.request(query, function(error, result) {
});

//Make an arbitrary GET request to the itunes connect API
var url = 'https://analytics.itunes.apple.com/analytics/api/v1/settings/user-info'; //Get info about yourself :)
var url = 'https://appstoreconnect.apple.com/analytics/api/v1/settings/user-info'; //Get info about yourself :)
instance.getAPIURL(url, function(error, result) {
console.log(JSON.stringify(result, null, 2));
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"contributors": [
"Marko Cungl"
],
"version": "0.5.0",
"version": "1.1.1",
"repository": "JanHalozan/iTunesConnectAnalytics",
"main": "src/analytics.js",
"files": [
Expand Down
43 changes: 31 additions & 12 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Itunes = function(username, password, options) {
this.options = {
baseURL: 'https://appstoreconnect.apple.com/olympus/v1',
loginURL: 'https://idmsa.apple.com/appleauth/auth',
settingsURL: 'https://analytics.itunes.apple.com/analytics/api/v1',
settingsURL: 'https://appstoreconnect.apple.com/analytics/api/v1',
appleWidgetKey: 'e0b80c3bf78523bfe80974d320935bfa30add02e1bff88ec2166c6bd5a706c42',
concurrentRequests: 2,
errorCallback: function(e) { console.log('Login failure: ' + e); },
Expand Down Expand Up @@ -47,17 +47,13 @@ Itunes.prototype.executeRequest = function(task, callback) {
uri: uri,
headers: this.getHeaders(),
timeout: 300000, //5 minutes
json: requestBody
}, function(error, response, body) {
if (!response.hasOwnProperty('statusCode')) {
error = new Error('iTunes Connect is not responding. The service may be temporarily offline.');
body = null;
} else if (response.statusCode == 401) {
error = new Error('This request requires authentication. Please check your username and password.');
body = null;
}

completed(error, body);
json: requestBody,
resolveWithFullResponse: true
}).then(response => {
completed(null, response.body)
callback();
}).catch(error => {
completed(error, null);
callback();
});
}
Expand All @@ -72,6 +68,29 @@ Itunes.prototype.login = function(username, password) {
json: {'accountName': username, 'password': password, 'rememberMe': false},
resolveWithFullResponse: true
}).catch((res) => {
if (res.statusCode === 412) {
const cookies = res.response.headers['set-cookie'];
const headers = {
'Content-Type': 'application/json',
Accept: 'application/json',
scnt: res.response.headers['scnt'],
'X-Apple-ID-Session-Id':
res.response.headers['x-apple-id-session-id'],
'X-Apple-Widget-Key': this.options.appleWidgetKey,
'X-Requested-With': 'XMLHttpRequest',
'X-Apple-Domain-Id': '3',
Cookie: cookies
.map((cookie) => cookie.split(';')[0])
.join('; '),
};
return request
.post({
url: `https://idmsa.apple.com/appleauth/auth/repair/complete`,
headers: headers,
resolveWithFullResponse: true,
});
}

if (res.statusCode !== 409) {
return Promise.reject(res);
}
Expand Down
2 changes: 1 addition & 1 deletion src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ var Query = function(appId, config) {
};

this.adamId = appId;
this.apiURL = 'https://analytics.itunes.apple.com/analytics/api/v1';
this.apiURL = 'https://appstoreconnect.apple.com/analytics/api/v1';

_.extend(this.config, config);

Expand Down