api.asApp is undefined in resolver, but storage works — tried everything

I’ve hit a wall trying to use api.asApp() inside a Forge resolver function. I’ve spent a lot of time on this and am out of things to check. I am hoping someone can help or confirm what I am seeing.

I’m building a Forge Custom UI app to prompt for a Jira board ID and in the back end use api.asApp() in a resolver to call /rest/agile/1.0/board/{boardId}/configuration

  • storage.get(...) and storage.set(...) work perfectly
  • app runs on nodejs22.14.0
  • tried on two different machines

However I get api is undefined inside the resolver: TypeError: Cannot read properties of undefined (reading ‘asApp’)

mainifest

app:
  runtime:
    name: nodejs22.x

function:
  - key: resolver
    handler: index.handler

src/index.js (resolver)

import Resolver from '@forge/resolver';
import { storage, api } from '@forge/api';

const resolver = new Resolver();

resolver.define('setBoardConfig', async ({ payload }) => {
  console.log('🧪 typeof api:', typeof api);
  console.log('🧪 api keys:', Object.keys(api || {}));

  const response = await api.asApp().requestJira(`/rest/agile/1.0/board/${payload.boardId}/configuration`);
  const data = await response.json();
  await storage.set(`board-config-${payload.projectKey}`, data);
  return { success: true };
});
1 Like

Looks almost perfect! Just a couple of small tweaks:

Make sure to import correctly:

import api, { route } from '@forge/api';

And use it like this:

const response = await api.asApp().requestJira(route`/rest/agile/1.0/board/${payload.boardId}/configuration`, {
  headers: { Accept: 'application/json' },
});
1 Like

I was so deep in the code and debugging logs that I completely missed double-checking the import itself. Your comment was exactly what I needed.

Also, thanks for the route tip… that was literally the very next issue I hit after fixing the import. Really appreciate the clear and actionable advice!

1 Like

Glad it helped! If it solved your issue, feel free to mark it as accepted so others can find it more easily. Thanks!

1 Like