Token end-point Code samples available ?
Hi,
I’ve seen that there are plenty of good code samples inside the API. I’ve also seen that all of them need the Access Token and that the https://developer.legrand.com/tutorials/0auth2-end-point-url/ url explains the process.
I have not found any code samples of Step 2 about get the access token and the new Refresh token to store for next call. Is there any code sample available somewhere? And the best : Is there any Python 2.7 sample ? :p Like for API functions calls ?
Thanks in advance.
Best regards
Hello Frederic,
Here is a Python code for /token request generated via Postman. To generate a new refresh token you just need to use the same code by replacing “code” value with “refresh_token” and using the refresh_token generated in your first call :
import requests
url = “https://partners-login.eliotbylegrand.com/token”
payload={‘client_id’: ‘7366fd4e-XXXX-XXXX-XXXX’,
‘grant_type’: ‘authorization_code’,
‘client_secret’: ‘GB-XXXXXXXXX,
‘code’: ‘eyJraWQiOiJjcGltY29yZV8wOTI1MjAxNSIsInZlciI6IjEuMCIsInppcCI6IkRlZmxhdGUiLCJzZXIiOiIxLjAifQ..H7XMIX6mKRA……’,
‘client_id’: ‘3dd2XXXXXXX’}response = requests.request(“POST”, url, headers=headers, data=payload, files=files)
print(response.text)
Hoping it will help you,
Have a good day,
Leslie – Community Manager
Hello Leslie,
Brilliant ! It works perfectly ! Just to correct 2 points in your script if it can help someone on the forum, client_id is defined twice (no need) and there is no files parameter defined (no need too, .request() has a signature without file).
I have a new issue at the very end of me script, when I try to run a scene, I receive
{“statusCode”:401, “message”:”Unauthorized. Supplied access token is invalid or doesn’t include required scope(s).”}
Which is very strange to me because i’m pretty sure that I’ve asked for this permission. Is there any needed permissions I miss ? How can I deal with this to resolve this last issue ?
Best regards.
Frederic
Hi Frederic,
Can you please send me (for confidentiality) your application ID and the exact request you want to send via the contact form ? I’ll then try to see if your app is well configured and your call correctly set
Have a good day,
Leslie – Community Manager
Hi Leslie,
Had you a chance to have a look to the permissions?
I’ve tried twice with python samples at the bottom of tha call and still
{“statusCode”:401, “message”:”Unauthorized. Supplied access token is invalid or doesn’t include required scope(s).”}
Thanks for your help.
Best regards.
Hello Frédéric,
I received your email, I don’t forget you ;). I’ll take a look at it as soon as I can (this afternoon or tomorrow)
Have a good day,
Leslie – Community Manager
You must be logged in to reply to this topic.