itunesconnect

itunesconnect is node.js module wrapping iTunes Connect Reporting API. It allows to query sales/downloads reports in super easy way.
Installation
$ npm install itunesconnect
If you want to have and access to comman-line tool itcreport
install itunesconnect globally. See more info about itcreport
.
$ npm install itunesconnect -g
$ itcreport --help
About reports
There are 2 different report types, ranked
and timed
.
Ranked report is sorted by number of downloads and it can be filtered and grouped by one of the constants. Ranked report result contains just a number of sales and/or proceeds regardless of time frame. Ranked is also ignoring interval
option. Good use case for ranked report is to get summary of sales and/or proceeds in some time period. You can also use filters
and group
to make your query more advanced.
Timed report result is a little bit more detailed. It's not sorted by number of sales or proceeds. It's embedding objects with number of sales grouped by interval
option. You should understand it more looking at the examples below.
It's hard to fuly understand Apple API without documentation so my description might have some errors. I strongly recommend to play with queries and results and try to understand different types. If you also want to improove description feel free to do so.
Basic example
This example shows how to fetch ranked report data from last 10 days and timed report from last 3 weeks with week
interval.
Query:
var itc = require("itunesconnect");
var Report = itc.Report;
var itunes = new itc.Connect('apple@id.com', 'password');
itunes.request(Report.ranked().time(10, 'days'), function(error, result) {
console.log(result);
});
itunes.request(Report('timed').time(3, 'weeks').interval('week'), function(error, result) {
console.log(result);
});
Result (ranked):
[
{
"key": 0,
"title": "App Name ",
"rptgDesc": "App",
"contentSpecificTypeId": 1,
"contentSpecificTypeName": "iOS App",
"contentGrpCd": "Apps",
"contentProviderId": 0,
"artistName": "Artist Name",
"contentProviderName": "Provider Name",
"units": 7684
},
{
"key": 0,
"title": "In App Name ...",
"rptgDesc": "In App",
"contentSpecificTypeId": 3,
"contentSpecificTypeName": "Auto-Renewable Subscription",
"contentGrpCd": "Apps",
"contentProviderId": 0,
"contentProviderName": "Provider Name",
"units": 2886
}
...
]
Result (timed):
Default group for timed report is null so it contains just all downloads.
[
{
"data": [
{
"date": "2014-07-14T00:00:00.000Z",
"units": 1234567
},
{
"date": "2014-07-21T00:00:00.000Z",
"units": 2345
},
{
"date": "2014-07-28T00:00:00.000Z",
"units": 987
},
{
"date": "2014-08-04T00:00:00.000Z",
"units": 456789
}
]
}
]
Query (timed) grouped by location:
var itc = require("itunesconnect");
var Report = itc.Report;
var itunes = new itc.Connect('apple@id.com', 'password');
itunes.request(Report('timed').time(3, 'weeks').interval('week').group('location'), function(error, result) {
console.log(result);
});
Result (timed) grouped by location:
[
{
"metadata": {
"key": "143461",
"title": "New Zealand",
"parent_key": "-100004"
},
"data": [
{
"date": "2014-07-14T00:00:00.000Z",
"units": 3
},
{
"date": "2014-07-28T00:00:00.000Z",
"units": 2
}
]
},
{
"metadata": {
"key": "143465",
"title": "China",
"parent_key": "-100004"
},
"data": [
{
"date": "2014-07-14T00:00:00.000Z",
"units": 9
},
{
"date": "2014-07-21T00:00:00.000Z",
"units": 18
},
{
"date": "2014-07-28T00:00:00.000Z",
"units": 15
},
{
"date": "2014-08-04T00:00:00.000Z",
"units": 7
}
]
},
...
]
More complex query
This example shows how to fetch ranked report data from last 2 days, both app sales and in-app sales with one of provided categories, grouped by content and returning both sales and proceeds (Moooooooooney).
Please note that limit property apply just to ranked reports
var itc = require("itunesconnect");
var Report = itc.Report;
var itunes = new itc.Connect('apple@id.com', 'password');
var query = Report('ranked', {
limit : 100,
filters : {
type: [
itc.type.inapp,
itc.type.app
],
category: [6001,6002,6003]
},
group: 'content',
measures: [itc.measure.units, itc.measure.proceeds]
}).time(2, 'days');
itunes.request(query, function(error, result) {
console.log(result);
});
Same query in chainable way
var query = Report
.ranked()
.time(2,'days')
.limit(100)
.category([6001,6002,6003])
.group('content')
.type([itc.type.inapp, itc.type.app])
.measures( [itc.measure.units, itc.measure.proceeds]);
Connect Class
Please also reffer to Connect class docs.
Connect(<username>, <password>, [options])
Available options:
options.concurrentRequests = Number
options.errorCallback = Function
options.loginCallback = Function
options.cookies = Array
If you want to cache login cookies use loginCallback and set cookies option
Please note that cookies have expiration date
var itc = require("itunesconnect");
var options = {
loginCallback: function(cookies) {
redis.set("cache-cookies", cookies);
}
}
redis.get("cache-cookies", function (err, cookies) {
if(!err) options.cookies = cookies;
});
var itunes = new itc.Connect('apple@id.com', 'password', options);
Query Class
Please also reffer to Query class docs.
To create new Query class instance please use Report helper functions.
Report(<type>, [config])
Report.ranked([config])
Report.timed([config])
Config Object:
config.start = String|Date
config.end = String|Date
config.interval = String
config.filters.content = Number|Array
config.filters.type = String|Array
config.filters.transaction = String|Array
config.filters.category = Number|Array
config.filters.platform = String|Array
config.filters.location = Number|Array
config.group = String
config.measures = Array
config.limit = Number
Constants
var itc = require("itunesconnect"),
itc.type.inapp
itc.type.app
itc.transaction.free
itc.transaction.paid
itc.transaction.redownload
itc.transaction.update
itc.transaction.refund
itc.platform.desktop
itc.platform.iphone
itc.platform.ipad
itc.platform.ipod
itc.measure.proceeds
itc.measure.units
Query Class Methods
query.date
Example:
query.date('2014-04-08', new Date());
query.date(new Date());
query.date('2014-04-08');
query.date('2014-04-08').time('3', 'months');
query.time
query.time(10, 'weeks');
query.date('2014-04-08').time('3', 'months');
query.group
Available options:
- content
- type
- transaction
- category
- platform
- location
Ranked report default is content
. Timed report default is null
query.group('transaction');
query.interval
Available options:
- day
- week
- month
- quarter
- year
Ranked report is ignoring this.
query.interval('day');
query.limit
Ranked report default is 100. Timed report is ignoring this.
query.limit(100);
query.measures
See Constants for available options
query.measures(itc.measure.units);
query.measures([itc.measure.units, itc.measure.proceeds]);
Filter Medthods
All filter methods take one parameter Value or Array of Values
query.content
Content is taking Number or Array of Number (Application ID).
query.content(1);
query.content([1, 2]);
query.content([1, 2]).content(3);
query.category
Visit Categories Cheet-Sheet wiki page for available options
query.category(6001);
query.category([6002, 6003]);
query.category([6001, 6002]).category(6003);
query.location
Visit Locations Cheet-Sheet wiki page for available options
query.location(6001);
query.location([6002, 6003]);
query.location([6001, 6002]).location(6003);
query.platform
See Constants for available options
query.platform(itc.platform.desktop);
query.platform([itc.platform.desktop, itc.platform.ipad]).platform(itc.platform.ipod);
query.transaction
See Constants for available options
query.transaction(itc.transaction.free);
query.transaction([itc.transaction.free, itc.transaction.paid]).transaction(itc.transaction.refund);
query.type
See Constants for available options
query.type(itc.type.app);
query.type([itc.type.inapp, itc.type.app]);
itcreport
Command-Line tool to get report results from console. It can output result to console or to to json file.
I strongly recommend to put username and password in config file so its not in bash history
$ itcreport --help
Usage: itcreport [options] [command]
Commands:
create-config <filename>
Creates new config file <filename>
ranked [options]
Ranked report
timed [options]
Timed report
Options:
-h, --help output usage information
-V, --version output the version number
-c, --config <filename> Specify config file
-h, --cachetime <seconds> Specify cache time for session cookies. Defaulting to 1800.
-f, --forcelogin Will ignore cached cookies and re-login.
-u, --username <username> iTunes Connect Username (Apple ID)
-p, --password <password> iTunes Connect Password
-s, --since <since> Specify since date. You can use format YYYY-MM-DD or simply 1day ...
-d, --date <date> Specify date (YYYY-MM-DD) Defaulting to today.
-g, --group <group> Group results by one of the following:
-A, --content <contentid> Filter by Content ID. [Repeatable value]
-L, --location <location> Filter by Location. Visit (...) for available options. [Repeatable value]
-C, --category <category> Filter by Category. Visit (...) for available options. [Repeatable value]
-P, --platform <platform> Filter by Platform. [Repeatable value]
-T, --transaction <transaction> Filter by Transaction Type. [Repeatable value]
-t, --type Filter by Content Type. [Repeatable value]
-M, --measure <measure> Result measures (units, proceeds). Defaulting to units. [Repeatable value]
-o, --outputfile <filename> Output file name. Will be saved as json.
Some examples ...
$ itcreport create-config sample.json
$ itcreport timed -c sample.json --since 1week
$ itcreport timed -c sample.json --since 1week -C 6001 -C 6002
$ itcreport timed -c sample.json --date 2014-01-01
itcreport strings
Same story as for constants
inapp
app
free
paid
redownload
update
refund
desktop
iphone
ipad
ipod
proceeds
units
$ itcreport timed -c sample.json --date 2014-01-01 --platform desktop --platform ipad
TODO
- Better tests
- More examples
Links
License
(The MIT License)
Copyright (c) 2014 Marek Serafin, itunesconnect module creator
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.