You can use webhooks to receive events about your app, such as when it has been installed.
You can create a server system that reflects the installation in real time by re-fetching the installation when you receive it.
Configuration.
If you include the URL in the "Webhook URL" in the app settings, you will be notified by POST request when the event listed in document occurs.
Usage Example.
The following will reacquire the installation with all changes to the app, regardless of the event.
// Runkit Example
const express = require('express')
const app = express()
const getSdk = require('obniz-cloud-sdk').getSdk
async function getAllInstalls(token) {
const sdk = getSdk(token);
const allInstalls = [];
let skip = 0;
while (true) {
// 取得
const result = await sdk.app({ skip });
for (const edge of result.app.installs.edges) {
allInstalls.push(edge.node);
}
if (!result.app.installs.pageInfo.hasNextPage) {
break;
}
skip += result.app.installs.edges.length;
}
return allInstalls;
}
async function showAllDevices() {
// get All installed devices with configrations
const installs = await getAllInstalls("apptoken_XXXXXXXXXXX");
for (const install of installs) {
console.log(`obniz ${install.id}\n access_token ${install.access_token}\n configs ${install.configs}`)
}
}
app.post('/webhook', async (req, res) => {
console.log("webhook accepted")
await showAllDevices();
})
app.listen(3000)