Skip to main content

Apteco API

Project description

apteco-api

A 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.

The apteco package 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) or open a GitHub issue.

Details

This Python package is automatically generated by the OpenAPI Generator project:

  • API version: v2
  • OrbitAPI spec version: 1.9.19.6190
  • Package version: 0.3.1
  • Build package: org.openapitools.codegen.languages.PythonClientCodegen
  • Generator version: 4.3.1

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

support@apteco.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apteco-api-0.3.1.tar.gz (266.3 kB view hashes)

Uploaded Source

Built Distribution

apteco_api-0.3.1-py3-none-any.whl (705.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page