Package: apteco-api
apteco-apiA Python wrapper package for the Apteco API to allow access to Apteco Marketing Suite™ resources.This package is auto-generated from the API specification,
with a Python class for each API model and a Python method call for each API endpoint.
It enables the user to interact with the API using pure Python,
and transforms Python method calls with Python objects into HTTP requests with JSON,
including deserializing the responses back into Python objects.Theaptecopackage builds further on this
to provide a rich API for creating FastStats selections, data grids and cubes,
including returning results directly as pandas DataFrames.Note:although this package is auto-generated, which should minimise the chance of bugs occurring in it,
some parts of it are untested and there remains the possibility of bugs caused by inconsistencies in the API specification
or errors in the API itself. If you do come across a bug or any unexpected behaviour,
please contact Apteco support (support@apteco.com)
oropen a GitHub issue.DetailsThis Python package is automatically generated by theOpenAPI Generatorproject:API version: v2OrbitAPI spec version: 1.9.19.6190Package version: 0.3.1Build package:org.openapitools.codegen.languages.PythonClientCodegenGenerator version: 4.3.1RequirementsPython 2.7 and 3.4+Access to an installation of the Apteco APIThe Apteco API, which also goes under the nameOrbit 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 & UsageYou can install the package the usual way from PyPI usingpip:pip install apteco-apiImport the package in Python using:importapteco_apiNote: the package follows the Python convention of a hyphen-in the package name
and underscore_in the import name.Getting StartedThe 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_usernameandmy_passwordbelow)
are the same credentials you would use to log in to your FastStats system or Apteco Orbit™.Logging inimportapteco_apiasaa# configure the API client to use your instance of the APIconfig=aa.Configuration(host='https://example.com/OrbitAPI')api_client=aa.ApiClient(configuration=config)# send a simple login requestsessions_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 credentialsconfig.api_key={'Authorization':login_response.access_token}config.api_key_prefix={'Authorization':'Bearer'}Since theconfigobject updated here is the configuration object forapi_client,
the latter will now be authorised to access the API.Retrieving data from an endpointThis code retrieves a list of tables in theHolidayssystem 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.namefortintables.list))Output:There are 9 tables in the Holidays system:
Households
People
Bookings
Communication Responsible
Insurance
Communications
Content
Responses Attributed
Journey HistoryLogging outYou can end your session using thelogout_sessionendpoint,
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')exceptaa.ApiExceptionase:print(f"{e.status}:{e.reason}")Output:401: UnauthorizedThe 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 theapi_client.configurationobject.General use of the API clientEvery section of the API (Audiences,FastStatsSystems,Queries,Sessions, etc)
has a corresponding controller class in theapteco-apipackage, named<section>Apie.g.SessionsApi, as seen above.To use endpoints from a given section,
create an instance of the controller by passing an [authorised]ApiClientobject
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 aQueryFileobject supplied as a keyword-only argument.
TheQueryFileobject 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 detailsAll 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.htmlfrom your API base URL,
e.g.https://example.com/OrbitAPI/swagger/ui/index.htmlHere, 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.AuthorApteco Ltdsupport@apteco.com