cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Not a customer? Start a free trial

Click the Start a free trial link to start a 15-day SaaS trial of our product and join our community as a trial user. If you are an existing customer do not start a free trial.

AppDynamics customers and established members should click the sign in button to authenticate.

Controller (SaaS, On Premises)

Python Code For Data Extraction using OAuth API Client

SOLVED
Vaibhav Vir.Singh
Architect

Python Code For Data Extraction using OAuth API Client

Team,

With recent release (4.5) we see "API Client" through which we can pull metric data via POST API.

Even though we have documentation available at https://docs.appdynamics.com/display/PRO45/API+Clients

But I have not been able to execute it successully, so thought to check with you.

 

In below code, we have API Client named 'test21' and Account i am taking by default that is customer1.

 

Appreciate your help. 

 

geturl = 'https://'+ControllerPort+'/controller/api/oauth/access_token'
client_secret = '<<Secret_Copied>>'
data = {'grant_type': 'client_credentials','Content-Type': 'application/vnd.appd.cntrl+protobuf;v=1'}
access_token_response = requests.post(geturl, data=data, verify=False, allow_redirects=False, auth=('test21@customer1', client_secret))
print(access_token_response.text)

 

 

By replying you agree to the Terms and Conditions of the AppDynamics Community.
Python Code For Data Extraction using OAuth API Client
13 REPLIES 13
Vaibhav Vir.Singh
Architect

Any thoughts and help in this?
Vaibhav Vir.Singh
Architect

Just realized this thread i raised did not have any solution marked.

 

I accomplished so sharing for broader community. 

 

replace 'token' with big token string without quotes in the headers.

 

################

import requests

 

headers = {

    'Authorization': 'Bearer token',

}

 

# Sample Query to fetch all applications

response = requests.get('https://<<CONTROLLERHOST>>:8181/controller/rest/applications', headers=headers, verify=False)

print(response.text) # OR response.content

################

 

Either you use Token directly like above, OR you can get token generated from secret of API Client like below: 

curl -k -X POST -H "Content-Type: application/vnd.appd.cntrl+protobuf;v=1" "https://<<CONTROLLER:8181/controller/api/oauth/access_token " -d “grant_type=client_credentials&client_id=XYZ@customer1&client_secret=4c45*****801”

 

Regards,

VVS

keshav.Swami
New Member

Hi 

To generate temporary access token using python, you can use request library of python .

 

 

  generate_token_url="https://<Controller URL>/controller/api/oauth/access_token"
  payload = {
    "grant_type":"client_credentials",
    "client_id":"Client_Id@ControllerName",
    "client_secret":"fe************************rf"
  }
  token_headers = { "Content-Type": "application/vnd.appd.cntrl+protobuf;v=1" }
  generate_token_response = requests.request("POST", generate_token_url, headers=token_headers, data=payload).json()
print(generate_token_response["access_token"])
 
you just need to change client_id and client_secret in payload
Ryan.Paredez
Community Manager

Hi, @keshav.Swami 

 

Thanks for sharing that information. This is a peer-to-peer community, so helping others is key to the community's success


Thanks,
Ryan, AppDynamics Community Manager



Found something helpful? Click the Accept as Solution button to help others find answers faster.
Liked something? Click the Thumbs Up button.