Demonstrated in Python.
>>> import xmlrpclib
>>> from pprint import pprint
Connect to Sklik API:
- https://api.sklik.cz/RPC2 is the XMLRPC/FastRPC endpoint always pointing to the current Sklik API version
- https://api.sklik.cz/bajaja/RPC2 is the current version of Sklik API
- https://api.sklik.cz/arabela/RPC2 is the previous version of Sklik API
New versions of Sklik API are created when we add features that break backwards compatibility.
>>> proxy = xmlrpclib.ServerProxy("https://api.sklik.cz/RPC2")
Login to "master" user account and get the session string using client.login:
>>> sess = proxy.client.login("[email protected]", password)["session"]
Get userId of the "slave" account using client.getAttributes:
>>> pprint(proxy.client.getAttributes(sess))
{'foreignAccounts': [{'access': 'rw',
'accountLimit': None,
'dayBudgetSum': 80000,
'relationName': '',
'relationStatus': 'live',
'relationType': 'normal',
'userId': 132256,
'username': '[email protected]',
'walletCredit': 0,
'walletCreditWithVat': 0,
'walletVerified': False}],
'session': '6|OVQF2V...BKFCA4VSVJGX2GQCS===',
'sessionStarted': <DateTime '20120712T14:03:02+0200' at 10e8ab0e0>,
'status': 200,
'statusMessage': 'OK',
'user': {'accountLimit': None,
'agencyStatus': 'normal',
'dayBudgetSum': 2602200,
'userId': 86796,
'username': '[email protected]',
'walletCredit': 0,
'walletCreditWithVat': 0,
'walletVerified': False}}
>>> slaveUserId = 132256
List report templates in your "master" account with listReportTemplates:
>>> pprint(proxy.listReportTemplates(sess))
{'reportTemplates': [{'email': None,
'endDate': None,
'id': 33138,
'name': u'Kampan\u011b Souhrn V\u010dera V\u0161echny kampan\u011b',
'runPeriod': None,
'startDate': None,
'timePeriod': 'yesterday'}],
'session': '6|OVQF2VSHKA...OFU4EF6VZX3I3QYPZ6K===',
'status': 200,
'statusMessage': 'OK'}
>>> reportTemplateId = 33138
Create a new report with report.createFromTemplate:
- report will be created using the report template from the "master" account,
- report will be placed in the "slave" account,
- report will contain data from "slave" acccount,
You can use report template from any account you have read-only or read/write access to. You need read/write access to the "slave" account.
>>> proxy.report.createFromTemplate(sess, reportTemplateId, slaveUserId)
{'status': 200, 'session': '6|OVQF2VS...YAZW7Y===', 'reportId': 5278611, 'statusMessage': 'OK'}
The report was created in the "slave" account:
>>> pprint(proxy.listReports(sess))
{'reports': [],
'session': '6|OVQF2...W4Y7VOVNAIWBHEY===',
'status': 200,
'statusMessage': 'OK'}
>>> pprint(proxy.listReports(sess, slaveUserId))
{'reports': [{'endDate': <DateTime '20120711T00:00:00+0200' at 10e8ab098>,
'generatedDate': <DateTime '20120712T14:04:43+0200' at 10e8ab200>,
'id': 5278611,
'name': u'Kampan\u011b Souhrn V\u010dera V\u0161echny kampan\u011b',
'requestDate': <DateTime '20120712T14:04:43+0200' at 10e8ab320>,
'startDate': <DateTime '20120711T00:00:00+0200' at 10e8ab248>,
'status': 'finished'}],
'session': '6|OVQF2VSHK...RK5TNVJBHPK3FB2===',
'status': 200,
'statusMessage': 'OK'}
You can retrieve the report using report.getAttributes :
>>> pprint(proxy.report.getAttributes(sess, 5278611))
{'report': {'campaignIds': None,
'context': True,
'data': {'header': ['id',
'campaignName',
'impressions',
'clicks',
'ctr',
'avgCpc',
'money',
'avgPosition'],
'rows': [[408367,
'Campaign in pmszn2',
0,
0,
None,
None,
0,
0.0]],
'summary': {'avgCpc': None,
'avgPosition': 0,
'clicks': 0,
'ctr': None,
'impressions': 0,
'money': 0}},
'endDate': <DateTime '20120711T00:00:00+0200' at 10e8ab3f8>,
'fulltext': True,
'generatedDate': <DateTime '20120712T14:04:43+0200' at 10e8ab2d8>,
'granularity': 'total',
'id': 5278611,
'itemsIncluded': 'allItems',
'name': u'Kampan\u011b Souhrn V\u010dera V\u0161echny kampan\u011b',
'reportType': 'campaign',
'requestDate': <DateTime '20120712T14:04:43+0200' at 10e8ab0e0>,
'startDate': <DateTime '20120711T00:00:00+0200' at 10e8ab248>,
'status': 'finished',
'userId': 132256},
'session': '6|OVQF2VS...BJMUSVFAWCC===',
'status': 200,
'statusMessage': 'OK'}