I want to make a rest api call and get access token and that access token will be there for 30 min. Again i need to refresh that token.
I am not getting how to get the access token, tried numerous code snippets.
Sample access token will be as below: KkcwAIyUm6XGbGUA0wejna6_8kk3Zuo66BigYo3gAGI.
URL used in post man to get access token manually: [https://xxx.xxx.com/restapi/vc/authentication/sessions/login?user.login=s_user&user.password=xxx]
Then i need to use this access token in below URL to fetch data: [https://xxx.xxx.com/restapi/vc/messages/id/879997?restapi.session_key=kEf-mTzu6Xnsa5HQKt8ml-9Wc-HX3wHLlphB2oQkrxE.&restapi.response_format=json]
Can anyone help with python code for this
Code i am trying for getting access token:
import requests
import json
with requests.Session() as session:
req = requests.get(r'https://xx.xx.com/restapi/vc/authentication/sessions/login?user.login=s_user&user.password=xxxx')
print(req.content)
Output: b'\n F0JQfxkxxwl-O9-cQKtJhdrNRKJg3ENLd_SckmBIqU0.\n\n'
Code working for hard coding access token from post man:
for m in data_list:
response = requests.get("https://xxx.xx.com/restapi/vc/messages/id/"+m+"?restapi.session_key=kEf-mTzu6Xnsa5HQKt8ml-9Wc-HX3wHLlphB2oQkrxE.&restapi.response_format=json")
data = response.json()
cleaned_text=cleanhtml(data['response']['message']['body']['$'])
body_list.append(cleaned_text)
#print(cleaned_text)
#print ('---------BODY ENDS HERE--------')
tz_subject = data['response']['message']['subject']['$']
When i hard code the access token that i got from post man i am able to fetch results using below code , but i am not getting how to generate access token in python and then use it, refresh it when i expires
Thanks you
reqvariable of the first snippet (which is actually a response). I don't see a need for a POST request here, GET should do. Usually data is in JSON form which can be decoded in a similar way as in the second snippet. Details how the token is saved in the JSON should be given by provider of the REST API.