API bad request from addon.on()

Hi. I use this code.

addon.on("host_settings_saved", async (clientKey, ctx) => {
const http = addon.httpClient({ clientKey });
http.get("/rest/api/3/group/bulk", () => {
// response error 400 Bad Request !!

But if I use a setTimeout(() => { … request }, 5000) then I get the result of the query. Please tell me what I’m doing wrong

I’m assuming you’re testing this immediately after installing the app in your instance, and right after the installed lifecycle webhook is received.

Please take into consideration that the host requires some time to process the installation and provision access for the user account of your app.

This is why you cannot immediately call the host REST API after installation. Waiting for 5 seconds will work in most occasions, but ultimately this is a race condition between you trying to access and the host system provisioning your account. I’d recommend waiting for 5 minutes before trying to access the REST API after installation or add a retry mechanism.

Yes you’re right.
What then is the best way to create a one-time configuration based on jiraApi data.

That depends on what you are trying to do. For instance, you might also implement a Just-in-Time configuration, where you configure the app at the first user interaction. Or you implement an event-based system that puts an event on the queue post-installation and tries to start configuration every minute. If it fails, it re-queues the event. Alternatively, you can also add a Configure or Get Started page that a user needs to navigate to and initiate the initial configuration of the app. These are all valid approaches, and there are likely more options available. Which one suits you best depends on your needs.