Active IQ and AutoSupport Discussions


Active IQ API and swagger_client

According to the code examples, you have to use the swagger_client:


The following is the getAccessToken API in Python:

from __future__ import print_statement

import time

import swagger_client

from import ApiException

from pprint import pprint


# create an instance of the API class

api_instance = swagger_client.AccessTokenApi()

tokenManageraccessToken =  # TokenManageraccessToken |



    # Generates a new access token using a valid refresh token.

    api_response = api_instance.get_access_token(tokenManageraccessToken)


except ApiException as e:

    print("Exception when calling AccessTokenApi->getAccessToken: %s\n" % e)


After some googling I found that swagger_client needs to be custom built:

How can the swagger_client library be installed in python? Typing pip install swagger_client doesn't work.


Re: Active IQ API and swagger_client

Hi Wouter,


You do not need to use the swagger client. You can just use the normal python HTTP client libraries to call the APIs.




Re: Active IQ API and swagger_client

This was missing in the documentation until recently.  Following up on the earlier response, you can do this with HTTPS.  Here's an example from some recent code (load in pip3 modules as needed) and set token_data to your existing refresh token:


# use our refresh token content to get the latest access token
conn = http.client.HTTPSConnection( "" )
conn_data = json.dumps( { "refresh_token": token_data } )
conn.request( "POST", "/v1/tokens/accessToken", conn_data )


# get the response from the HTTPS request
res = conn.getresponse()
if res.status != 200:
    print( "Could not get new token data based on current refresh token:", res.status, res.reason )
    return None


# grab the token data
conn_data = json.loads( "utf-8" ) )


# reference conn_data['refresh_token'] or conn_data['access_token'] - remember to save the new refresh token!

View solution in original post

Check out the KB!
Knowledge Base
All Community Forums