Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Sample applications can be created in C#, JAVA, PYTHON languages based on the Swagger code generation.
This article describes how to:
- Generate the Python client code from Swagger.
- Use the client-side code to get available datasets.
The sample application doesn't cover all the method of calling APIs for other functionalities. However, the process of calling other APIs remains the same as outlined in this article.
How to run the application
Generate the client. Python is used in this example. Other clients can be generated from the Swagger.
Copy the contents of the OpenAPI spec from the endpoint. Paste the contents into Swagger Editor.
Select Generate Client > Python.
A Python client is generated/downloaded in the local system. On extracting, the following autogenerated files are available.
Create a file sample.py within the extracted folder. In this file, we call the generated Python code to invoke the APIs using the following code.
Provide the token value within the token variable
from __future__ import print_function import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # Configure API authorization token='<provide bearer token>' # create an instance of the API class api_instance = swagger_client.ScheduledDatasetApi(swagger_client.ApiClient()) api_instance.api_client.set_default_header("Authorization", "Bearer "+token) dataset_name = 'Wishlist' # str | (optional) try: # Get available datasets and it's information such as columns, aggregations, pre defined dateranges etc api_response = api_instance.insights_v11_scheduled_dataset_get(dataset_name=dataset_name) pprint(api_response) except ApiException as e: print("Exception when calling ScheduledDatasetApi->insights_v11_scheduled_dataset_get: %s\n" % e)
Install the dependencies.
Use the following commands to install dependencies and setup:
pip install -U pip setuptools python setup.py install
Run the code.
python sample.py
The following response is generated from the code.
Similarly, other APIs can be invoked from the code as shown in this example.