Get all apps in the account

Question / Problem

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']

image
I ran the following code but encountered a CORS error (I have hidden the username and password)
image

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)

Hello @Hoang_Viet

Apologies for overlooking your attachment.

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:

(function() {
    'use strict';

    const apiUrl = '/k/v1/apps.json';

    function fetchAllApps() {
        return kintone.api(kintone.api.url(apiUrl, true), 'GET', {})
            .then(response => {
                return response.apps.map(app => app.name);
            })
            .catch(error => {
                console.error('API call failed:', error);
                throw error;
            });
    }

    // Execute the function to fetch all apps
    fetchAllApps().then(appNames => {
        console.log('All apps:', appNames);
        alert('All apps: ' + appNames.join(', '));
    });

})();
1 Like

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

Hi Hoang

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:

1 Like

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}`);
});

Eror after call api:
image

1 Like

I have found a solution to this issue. Thank you everyone for your enthusiastic support, Chris and Will-Yama. Thank you all very much

1 Like