Active IQ and AutoSupport Discussions

Active IQ API and swagger_client

WouterC
4,420 Views

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 swagger_client.rest import ApiException

from pprint import pprint

 

# create an instance of the API class

api_instance = swagger_client.AccessTokenApi()

tokenManageraccessToken =  # TokenManageraccessToken |

 

try:

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

    api_response = api_instance.get_access_token(tokenManageraccessToken)

    pprint(api_response)

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: https://github.com/swagger-api/swagger-codegen/#generating-libraries-from-your-server

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

1 ACCEPTED SOLUTION

mattaparity
3,901 Views

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( "api.activeiq.netapp.com" )
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( res.read().decode( "utf-8" ) )

 

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

View solution in original post

2 REPLIES 2

BuddyT
4,235 Views

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.

 

 



 

mattaparity
3,902 Views

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( "api.activeiq.netapp.com" )
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( res.read().decode( "utf-8" ) )

 

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

Public