Apteco API
Project description
apteco-api
A wrapper package for the Apteco API to allow access to Apteco Marketing Suite™ resources
This Python package is automatically generated by the OpenAPI Generator project:
- API version: v2
- OrbitAPI spec version: 1.8.13.2139
- Package version: 0.2.0
- Build package:
org.openapitools.codegen.languages.PythonClientCodegen
Requirements
- Python 2.7 and 3.4+
- Access to an installation of the Apteco API
The Apteco API, which also goes under the name Orbit API, is part of the Apteco Orbit™ installation. If you are unsure whether you have access to this, please contact Apteco support (support@apteco.com).
Note: the examples in this guide use Python 3.6+
Installation & Usage
You can install the package the usual way from PyPI using pip
:
pip install apteco-api
Import the package in Python using:
import apteco_api
Note: the package follows the Python convention of a hyphen -
in the package name
and underscore _
in the import name.
Getting Started
The examples below shows how to connect to the API, log in to create an access token, retrieve some data from one of the API's endpoints, and then log out.
Note: your login credentials (my_username
and my_password
below)
are the same credentials you would use to log in to your FastStats system or Apteco Orbit™.
Logging in
import apteco_api as aa
# configure the API client to use your instance of the API
config = aa.Configuration(host='https://example.com/OrbitAPI')
api_client = aa.ApiClient(configuration=config)
# send a simple login request
sessions_controller = aa.SessionsApi(api_client)
login_response = sessions_controller.sessions_create_session_simple(
'my_data_view', 'my_username', 'my_password'
)
# keep a copy of the session ID (needed to log out)
session_id = login_response.session_id
# update the configuration with your credentials
config.api_key={'Authorization': login_response.access_token}
config.api_key_prefix={'Authorization': 'Bearer'}
Since the config
object updated here is the configuration object for api_client
,
the latter will now be authorised to access the API.
Retrieving data from an endpoint
This code retrieves a list of tables in the Holidays
system on the given DataView:
tables = aa.FastStatsSystemsApi(api_client).fast_stats_systems_get_fast_stats_tables(
'my_data_view',
'holidays'
)
print(f"There are {tables.count} tables in the Holidays system:")
print('\n'.join(t.name for t in tables.list))
Output:
There are 9 tables in the Holidays system:
Households
People
Bookings
Communication Responsible
Insurance
Communications
Content
Responses Attributed
Journey History
Logging out
You can end your session using the logout_session
endpoint,
and passing in the session ID returned from the logging in process above:
aa.SessionsApi(api_client).sessions_logout_session('my_data_view', session_id)
try:
tables = aa.FastStatsSystemsApi(api_client).fast_stats_systems_get_fast_stats_tables(
'my_data_view',
'holidays'
)
except aa.ApiException as e:
print(f"{e.status}: {e.reason}")
Output:
401: Unauthorized
The first line successfully ended the session and so, as expected, the attempt to retrieve the tables data failed and raised an exception.
Note that logging out like this ends the session on the server-side,
but it doesn't remove the copy of the (now invalid) access token kept in the
api_client.configuration
object.
General use of the API client
Every section of the API (Audiences
, FastStatsSystems
, Queries
, Sessions
, etc)
has a corresponding controller class in the apteco-api
package, named <section>Api
e.g. SessionsApi
, as seen above.
To use endpoints from a given section,
create an instance of the controller by passing an [authorised] ApiClient
object
as the single argument to its constructor:
queries_controller = aa.QueriesApi(api_client)
This object then has a method corresponding to each endpoint of that section of the API, which can be called as a normal Python function.
query_result = queries_controller.queries_perform_query_file_count_synchronously(
'my_data_view',
'holidays',
query_file=aa.QueryFile('Private/Bookings to France or Germany.xml')
)
Some of the parameters for this function may need to be specific object types;
in the example here, the first two parameters are strings specifying the DataView and FastStats system to use for the query,
while the path of the file for the query is given via a QueryFile
object supplied as a keyword-only argument.
The QueryFile
object itself is initialised with a single argument, namely the filepath.
Similarly, the function call returns a Python object. These API functions often return 'result' objects which bundle together various data and metadata as attributes, and these attributes can then be accessed to obtain the information of interest.
count = query_result.counts[0]
print(f"The query matched {count.count_value:,} {count.table_name.lower()}.")
Output:
The query matched 985,734 bookings.
Further details
All classes and methods have detailed docstrings providing further information about their parameters and return values.
You can also explore the API in a visual way by going to /swagger/ui/index.html
from your API base URL,
e.g. https://example.com/OrbitAPI/swagger/ui/index.html
Here, each section of the API is listed, and clicking on one will expand the view to show all the endpoints that belong to it. Clicking on an endpoint will similarly expand that to detail its parameters and show example values for using it. You can also try out endpoints directly within the interface, and view the returned data.
Author
Apteco Ltd
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for apteco_api-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30825c648a7a851b6d1d38de7fa2e87f335cf72750c8e802dcb98d3ee6b8060 |
|
MD5 | 2985d8cd3c0877e0a91e33c04f57f19c |
|
BLAKE2b-256 | dbba8cffc5be00002022bf914978b059b0379f9ddda8e7649763ec45beb3fb89 |