Question / Problem
Condition for opening the app through the status of an external API.
Current Situation
I'm having an issue with the Kintone app. I want to call an external API before entering and displaying data in the app. This API will take the login ID as a parameter. If the response returns false, no operations will be allowed in the app, and the list data of the app will not be viewable. If the response returns true, normal operations with the Kintone app will be allowed. I'm using JavaScript and CSS Customization to add a JS file to check the kintone.events.on("app.record.index.show", function (event) event, but it's not working. I would greatly appreciate any support from everyone.
Code / Attempts
kintone.events.on("app.record.index.show", function (event) {
const user = kintone.getLoginUser();
const query = "JavaScript";
const apiUrl = `https://www.googleapis.com/books/v1/volumes?q=${query}`;
const payload = {
id: user.code,
};
fetch(apiUrl, {
method: "GET",
headers: {
"Content-Type": "application/json",
// Authorization: "Bearer your_token_here",
},
// body: JSON.stringify(payload),
})
.then((response) => {
if (response) {
//When call api successful then the Kintone app will be allowed
alert("The API call was successful");
return true;
}
})
.catch((error) => {
// If call api failed, not show app kintone
alert("Error: " + error.message);
return false;
});
return event;
});