Transactional API Library

Highlighted
Community Boss

Transactional API Library

With the general announcement of the new Transactional API, I'm happy to share a simple Python library to help users utilise this new feature. This library was written with version 3.8.0 of Python, and requires installation of the Cryptography library. All other packages used are included in standard Python installations.

 

Steps to use:

1. After adding the attached scripts to your project, start by setting up your Anaplan connection, which will be used in all subsequent steps. The four details required for certificate authentication with Java Keystore (best practice), are: path to the keystore, keystore passphrase, keystore alias, and the passphrase of the private key. Next, you will generate the auth token used for your API requests and store that in an Anaplan Connection object, along with your workspace and model IDs

 

Screenshot 2020-11-10 at 21.13.09.png

 

2. Now that your Anaplan connection object is created, you can fetch the list of modules from your Anaplan model to select the module and view you wish to work with.

 

Screenshot 2020-11-11 at 11.35.01.png

 

In the code snippet above, you can see that I start by fetching the full list of modules from my model. This returns a JSON array of the available modules. I pass this to the Anaplan Resource Dictionary class, which builds a key-value dictionary (where the module name is the key and its ID is the value). Once created, I pull the module ID for the SQL Demo module. With this ID, I request the list of views available and create a new key-value dictionary so I can select find the ID for the default view. If you're working with another named view, you would simply replace default with that value.

 

3. With the ID of module view you wish to extract, you have two options for extracting the data from Anaplan:

  1. JSON
  2. CSV

Screenshot 2020-11-11 at 11.43.10.png

 

In the first line, you can see I downloaded the cell data of the module view in JSON format, this returns a 2-dimensional array, while in the second line you'll see I'm downloading the entire view in CSV format. You have the option the request a specific dimension and item from the view by adding the respective IDs to get_view_data, after specifying your response type. Here, I'm extracting all data from the view

 

One of the most exciting, new features is the ability to set current model period via API. Currently, this must be done manually within your Anaplan model, but with transactional API, it is done with a simple request.

 

Screenshot 2020-11-11 at 12.16.32.png

 

Here, I call the set_current_period function, providing my connection object and the current period in YYYY-MM-DD format. If you provide a date outside the model calendar, our server will respond with an HTTP 400 Bad Request error.

 

Additionally, you can use the transaction API to view workspace allowance details. When creating the Anaplan Connection object, provide your workspace ID and use the get_workspace_details method to retrieve its current size, total allowance, and remaining workspace size.

 

Screenshot 2020-11-11 at 17.14.54.pngScreenshot 2020-11-11 at 17.15.02.png

Here, simply pass in your connection object, and the library will extract the workspace ID to fetch the requested information. This library is hard-coded to return workspace details in GB, but a simple alteration of anaplan.get_workspace_details allows you to return in KB, MB, etc.



Jesse Wilson
Solution Architect - Data Integrations
Singapore
1 REPLY 1
Highlighted
Occasional Contributor

Re: Transactional API Library

Having struggled with challenges in the earliest iterations of AnaplanConnect, I am SO thrilled by this new feature. Thanks for sharing your solution!

-Rachel