I want to call Kintone's API to get all the apps in that account. I see that the API token is limited to one app (can be used in a specific app). So how can I call an API to get all the apps I have in Kintone? Thank you very much.
Current Situation
My account has two apps: App1, App2. So how do I call api kintone and result return an array ['App1', 'App2']
I ran the following code but encountered a CORS error (I have hidden the username and password)
Hello @Hoang_Viet,
To retrieve a list of all apps in your Kintone account, you can use the Kintone API endpoint /k/v1/apps.json. This endpoint allows you to get information about all the apps you have access to in your Kintone environment.
Thank you for your answer, Chris. Above, I also showed the current code snippet to get the list of apps, but there's a CORS error when calling it. Can you check the code snippet above for me (I have hidden the username and password)
I suspect the script encounters a CORS error because it attempts to call the Kintone API directly from the browser using the fetch method. This is blocked by browsers as a security measure against cross-origin requests (requests to different origins like domains, protocols, or ports).
To circumvent CORS issues, it's recommended to use the kintone.api method provided by Kintone for API calls within the Kintone environment. This method handles authentication and CORS automatically. Here's an example:
Thank you for your answer, Chris. The situation I'm facing is that I need to call the Kintone API from one of our web applications (outside the Kintone
environment) to get the list of apps using our Kintone account and password.
Is there a way to do this? I am referring to the following method to call the API to get all Kintone apps from outside the Kintone environment using this link: Get Apps - Kintone Developer Program
The main problem as Chris pointed out, is that a browser-to-browser request will not work due to security issues (i.e. the CORS errors).
What you need to do, is to make a request to a server you own, and make the REST API call from that server (server-to-browser requests do not cause CORS errors). The response will be given back to your server, which you can feed back to your browser.
I wrote a tutorial series a while back covering how to do this - I hope it helps:
Thank you for your answer, will-yama. Below, I have a test code to get the list of apps through the REST API (I coded it with Express of Node.js), but I am encountering an error as shown in the image below. I would really appreciate your help. Thank you very much.
File express ( be)
import cors from 'cors';
import fetch from 'node-fetch';
const PORT = 5000;
const app = express();
app.use(cors());
const corsOptions = {
origin: "http://localhost:3000"
};
//Domain: https://d1456jgrh5qr.cybozu.com/login?saml=off
const requestEndpoint = "https://d1456jgrh5qr.cybozu.com/k/v1/apps.json";
//I'm hiding accoutn and password
const encodedString = Buffer.from('account:password').toString('base64');
// This function runs if the http://localhost:5000/getData endpoint
// is requested with a GET request
app.get('/getData', cors(corsOptions), async (req, res) => {
const fetchOptions = {
method: 'GET',
headers: {
'X-Cybozu-Authorization': encodedString,
'Content-Type': 'application/json',
}
}
try {
const response = await fetch(requestEndpoint, fetchOptions);
console.log('response ', response)
if (!response.ok) {
throw new Error(`Network response was not ok ${response.statusText}`);
}
const jsonResponse = await response.json();
res.json(jsonResponse);
} catch (error) {
res.status(500).json({ message: error.message });
}
});
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`);
});