Save data with a Google Script


#1

Hello

I am french, sorry for my english.

I try to save data with a google script, but i have a problem to creat the push request in google script langage… I have one for the post netatmo api, and works, but it still not works for exosite api… Can you help me ?

This is my google script code :

// Variables :
var payload;
var options;
var reponse;

// Construit la requête de type post
payload =
{
  "X-Exosite-CIK" : "2b9a3ec......",
  "Content-Length" : "20 Cuve=1200"
};
   
options =
{
  "method" : "post",
  "payload" : payload
   //muteHttpExceptions : true
};

// Envoie la requête de type POST     
reponse = UrlFetchApp.fetch("http://m2.exosite.com/api:v1/stack/alias", options);
Logger.log(reponse.getContentText("UTF-8"));

The answer is HTTP/1.1 401 Unauthorized


#2

Your CIK needs to be in a header, not the payload of the request. I’m not able to test this, but I think you’d need to do something like this:

payload = "Cuve=1200";

headers = 
{
  "X-Exosite-CIK": "00000000..."
};

options =
{
  "method" : "post",
  "payload" : payload,
  "headers": headers
};

reponse = UrlFetchApp.fetch("http://m2.exosite.com/api:v1/stack/alias", options);
Logger.log(reponse.getContentText("UTF-8"));

#4

thank you for your answer

but i have tried your solution ; i have the same error :frowning:


#5

I you want to PM me your CIK, I can setup logging on our end so that we can see exactly what our server is receiving and see where the problem is.


#6

i am sorry, i don’t find where i have to click to pm… it doesn’t matter for my cik if it is public… (i will edit when you answer me)

this is my code :smile:

 // Construit la requête de type post
    headers = {"X-Exosite-CIK":"2b9a3ec99198c7ad84b7e063c779aec9db0581a5"};
    
    payload = "Cuve=1200";
       
    options =
    {
      "method" : "post",
      "headers" : headers,
      "payload" : payload
      
      
       //muteHttpExceptions : true
    };

reponse = UrlFetchApp.fetch("http://m2.exosite.com/api:v1/stack/alias", options);
Logger.log(reponse.getContentText("UTF-8"));

#7

Ah, shoot. It seems our internal debug logging hasn’t been set back up yet since we made some changes to our load balancing.

But anyway, that doesn’t appear to be a valid CIK. You should double check that you’ve copied it right and if it’s a client model based (ie not generic) device you need to make sure it’s been activated.


#8

Hi, I have check the CIK and i should have change… I don’t know why, but now, all works fine !

Thanks very much !!! :smile:


#9

Great! You’re very welcome!