Home + Control – Get User\'s Plants
Hello
I’m just trying to test the API to develop a little web app.
I’ve subscribed to the Starter Kit and got the 2 keys.
But when try to get user plants (i have one living now gateway connected) i always receive the follow error:
Request-Context: appId=cid-v1:17d898fc-adbd-487e-96a4-c4287796f34d
Date: Sun, 08 Mar 2020 12:04:00 GMT
Content-Length: 52
Content-Type: application/json
{
“statusCode”: 401,
“message”: “JWT not present.”
}
My request is the following (primary key used)
GET https://api.developer.legrand.com/hc/api/v1.0/plants HTTP/1.1
Host: api.developer.legrand.com
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
Also tried with php client and also tried adding the
‘Authorization’ => ‘***********************’ (with both the primary and secondary key)
Where I’m wrong?
Please help me!
Thanks in advance
Francesco
Hi Francesco,
You’re missing the “access_token“.
You need to have your subscription key (“Ocp-Apim-Subscription-Key“) and an access token (“Authorization“).
You have to grab the access token using step 2 of this tutorial : https://developer.legrand.com/tutorials/0auth2-end-point-url/
Then, you have to do something like that:
$opts[CURLOPT_HTTPHEADER][]=’Ocp-Apim-Subscription-Key: ‘. $data[‘Ocp-Apim-Subscription-Key’];
$opts[CURLOPT_HTTPHEADER][]=’Authorization: Bearer ‘ . $data[‘Authorization’];
Thierry
Thanks Thierry,
i’ve tried but can’t receive the code from step 1 of the tutorial:
this is the response i get: a blank page with only:
Eliot Authentication Proxy
Can be a matter of redirect_uri? what i have to put on that page?
here is the request:
(sure with a valid client_id taken from the email when submitted the app)
and here is the source code of the response page:
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″ />
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″ />
<link href=”/images/favicon.ico” rel=”shortcut icon” type=”image/x-icon” />
<title> – Eliot.Authentication.Proxy.Web</title>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css” />
<meta name=”x-stylesheet-fallback-test” content=”” class=”sr-only” />
<script>
!function(a,b,c,d){var e,f=document,g=f.getElementsByTagName(“SCRIPT”),h=g[g.length-1].previousElementSibling,i=f.defaultView&&f.defaultView.getComputedStyle?f.defaultView.getComputedStyle(h):h.currentStyle;if(i&&i[a]!==b)for(e=0;e<c.length;e++)f.write(‘<link href=”‘+c[e]+'” ‘+d+”/>”)}(“position”,”absolute”,[“\/lib\/bootstrap\/dist\/css\/bootstrap.min.css”], “rel=\u0022stylesheet\u0022 “);
</script>
<link rel=”stylesheet” href=”/css/site.min.css?v=1NjhtDH1GiYovTzHs06vPf5bh2bBctp38DShcW55ZyM” />
<script type=”text/javascript”>
var appInsights=window.appInsights||function(a){
function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement(“script”);b.src=a.url||”https://az416426.vo.msecnd.net/scripts/a/ai.0.js”,d.getElementsByTagName(“script”)[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=[“Event”,”Exception”,”Metric”,”PageView”,”Trace”,”Dependency”];f.length;)b(“track”+f.pop());if(b(“setAuthenticatedUserContext”),b(“clearAuthenticatedUserContext”),b(“startTrackEvent”),b(“stopTrackEvent”),b(“startTrackPage”),b(“stopTrackPage”),b(“flush”),!a.disableExceptionTracking){f=”onerror”,b(“_”+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c[“_”+f](a,b,d,e,h),i}}return c
}({
instrumentationKey: ‘b3055cfd-9e5a-4ff8-8670-fe7d81222948’
});
window.appInsights=appInsights,appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();
</script>
</head>
<body>
<div class=”container”>
<h1>Eliot Authentication Proxy</h1>
</div>
<script src=”https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js” crossorigin=”anonymous”
integrity=”sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk”>
</script>
<script>
(window.jQuery||document.write(“\u003Cscript src=\u0022\/lib\/jquery\/dist\/jquery.min.js\u0022 crossorigin=\u0022anonymous\u0022 integrity=\u0022sha384-K\u002BctZQ\u002BLL8q6tP7I94W\u002BqzQsfRV2a\u002BAfHIi9k8z8l9ggpc8X\u002BYtst4yBo\/hH\u002B8Fk\u0022\u003E\u003C\/script\u003E”));
</script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js” crossorigin=”anonymous”
integrity=”sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn”>
</script>
<script>
(window.jQuery && window.jQuery.fn && window.jQuery.fn.modal||document.write(“\u003Cscript src=\u0022\/lib\/bootstrap\/dist\/js\/bootstrap.min.js\u0022 crossorigin=\u0022anonymous\u0022 integrity=\u0022sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk\u002B02D9phzyeVkE\u002Bjo0ieGizqPLForn\u0022\u003E\u003C\/script\u003E”));
</script>
<script src=”/js/site.min.js?v=eHkHX-wpSfK5dHPf2Z62OXaZUKax21jI4-Fu0Tixm9Q”></script>
</body>
</html>
I think your URL is wrong:you forgot “authorize”.
Try that:
https://partners-login.eliotbylegrand.com/authorize?client_id=**********************&redirect_uri=http://francescotarquini.ddns.net/domo/testhomeplus/&response_type=code
Also, the “redirect_uri” should point to a callback page.
Thierry
THANKS A LOT Thierry!!!
Now it works like a charm!
Just one last question about the token:
The access token is valid for one hour right?
So if a deploy an application, will have to take care of refreshing the token before making any request if the previous request was more than one hour before?
Am i right?
I have to implement a mechanics to refresh and safely store my access code server side and the client application (eg browsers or mobile app) ask the code to the server or is better to do it ALL client side (within mobile app for example)?
Thanks again really!
Francesco
Yep. According to the tutorial, the access_token is valid only one hour.
So, you have to refresh it regularly using a post request to https://partners-login.eliotbylegrand.com/token
I’m planning to implement the refresh functionnality in my program using a cron every 30 minutes. So it should be server side.
To be tested 🙂
Hello,
I confirm what Thierry said 😉
Thanks a lot for helping the community
Have a good day,
Leslie – Community Manager
Hi,
I use https://api.developer.legrand.com/hc/api/v1.0/plants to retrive at first my plants of my biticino xw8002
I receive an correct HTTP/1.1 200 OK response but plants lists are empty
{“plants”:[]}* Connection #0 to host api.developer.legrand.com left intact
I thought I was receivings something like:
“plants”: [
{
“id”: “some id string”,
“name”: “casa”,
“country”: “Europe\Rome”
}
]
what’s wrong
Thank
You must be logged in to reply to this topic.