I wish to drain your initial time
Swagger-Codegen allow us to create the interface automatically for a lot of langauges, here Python. More info.
Requirements:
Java jdk 8+
Know swagger version of Ivoz Avpi ( Ivoz now is 2.0)
# Create Python package for Ivozprovider API :
or if you have problems with ssl, can be a file downlaoded
java -jar swagger-codegen-cli-2.4.12.jar generate -i swagger.json -l python
The package can be customizable( name...) but I write the essentials.
Example code:
from __future__ import print_function
import time
import swagger_client
from swagger_client.api.provider_api import ProviderApi
from swagger_client.rest import ApiException
import json
from pprint import pprint
# Configure API key authorization: bearer
configuration = swagger_client.Configuration()
configuration.api_key['Authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
configuration.api_key_prefix['Authorization'] = 'Bearer'
configuration.host = 'https://xxxxxxxxxxxxx/api/brand'
configuration.verify_ssl = False
# # create an instance of the API class
api_instance = swagger_client.AuthApi(swagger_client.ApiClient(configuration))
username = 'aaaaaaaaaaaaa' # str |
password = 'bbbbbbbbbbbb' # str |
try:
# Retrieve JWT token
api_instance.post_admin_authenticate(username, password)
configuration.api_key['Authorization'] = json.loads(api_instance.api_client.last_response.data)['token']
except ApiException as e:
print("Exception when calling AuthApi->post_admin_authenticate: %s\n" % e)
provider_api_client = swagger_client.ProviderApi(swagger_client.ApiClient(configuration))
provider_api_client.get_company_collection()
And magic appears, all methods into provider_api_client, and first invocation to get all companies.
We write :)