paul2
(Paul A East)
April 8, 2022, 3:10pm
1
Hi Guys, I’m a amateur dev!!
I have managed to use google script app to look at the unlocking and locking in the logs to figure out the time my housekeepers are at the house. Using get of the API
I am now trying to figure out how to use the post parts of the api. I am trying to use the [POST] Updates asynchronous a smartlock authorization
var url = "https://api.nuki.io/smartlock/179??????????5/auth/62???????????????????40";
var headers = {
"Authorization": "Bearer 3b8567?????????????????????????????????????????????????????????????3cac451",
"contentType": "application/json",
"headers": {
"name": "A??????st",
"allowedFromDate": "2022-04-08T18:00:00.000Z",
"allowedUntilDate": "2022-04-11T11:00:00.000Z",
"allowedWeekDays": 0,
"allowedFromTime": 0,
"allowedUntilTime": 0,
"accountUserId": 0,
"enabled": true,
"remoteAllowed": false
}
};
var response = UrlFetchApp.fetch(url, headers);
var smartLocksData = JSON.parse(response.getContentText());
Error message: Exception: Request failed for https://api.nuki.io returned code 401. Truncated server response: {“detailMessage”:“Your access token is not authorized”,“stackTrace”:[],“suppressedExceptions”:[]} (use muteHttpExceptions option to examine full response)
Im using the same authorisation on my GET requests
paul2
(Paul A East)
April 11, 2022, 9:56am
2
Im suspecting I need to implement OAuth2 for POST/update request. Is this True?
Does anyone have any Docs to help to do this with google sheets?
paul2
(Paul A East)
April 13, 2022, 10:31am
3
I cannot figure this one out. Ive got to here but I cannot seen to invoke the POST call.
Everywhere I put
"method" : "post",
It does not seem to like it.
code below is returning all my auths. I guess its just invoking the Get method
var url = "https://api.nuki.io/smartlock/auth";
var headers = {
"Authorization": "Bearer 45??????????????????????????????????????????????6481",
};
var body = {
"name": "A?????????t",
"allowedFromDate": "2022-04-11T07:27:15.131Z",
"allowedUntilDate": "2022-04-11T07:27:15.131Z",
"allowedWeekDays": 0,
"allowedFromTime": 0,
"allowedUntilTime": 0,
"accountUserId": 0,
"enabled": true,
"remoteAllowed": false,
"id": "6????????????????????????0"
}
var options = {
headers: headers,
payload : body
};
var response = UrlFetchApp.fetch(url, options);
var smartLocksData = JSON.parse(response.getContentText());
Logger.log(smartLocksData);
paul2
(Paul A East)
April 13, 2022, 3:07pm
4
Ive figured it out
var url = "https://api.nuki.io/smartlock/auth";
var payload = [{
name: "A??????????t",
allowedFromDate: "2022-04-11T07:27:15.131Z",
allowedUntilDate: "2022-04-11T07:31:15.131Z",
allowedWeekDays: 0,
allowedFromTime: 0,
allowedUntilTime: 0,
accountUserId: 0,
enabled: true,
remoteAllowed: false,
id: "6????????????????????????0"
}];
var headers = {
method: "POST",
contentType: "application/json",
headers: {
Authorization: "Bearer 45?????????????????????????????????????????????????????????????6481",
accept: "application/json",
},
payload: JSON.stringify(payload)
}
var response = UrlFetchApp.fetch(url, headers);
var smartLocksData = response.getResponseCode();
Logger.log(smartLocksData);