Forge App cannot access storage API when module has endpoint resolver

Hi guys. I’m developing a small Forge app which should make requests to my API. Currently I use 2 modules, that’s from the manifest.yml:

jira:issuePanel:
    - key: my-issue-panel
      icon: https://developer.atlassian.com/platform/forge/images/icons/issue-panel-icon.svg
      render: native
      resolver:
        endpoint: remote-issue-panel
      resource: main
      title: Title
  jira:issueAction:
    - key: my-issue-action
      render: native
      resolver:
        function: resolver
      resource: action
      title: My settings
  function:
    - key: resolver
      handler: index.handler
  endpoint:
    - key: remote-issue-panel
      remote: remote-backend
      auth:
        appUserToken:
          enabled: true
        appSystemToken:
          enabled: true
permissions:
  scopes:
    - read:app-user-token
    - read:app-system-token
    - read:jira-user
    - read:jira-work
    - read:servicedesk-request
    - storage:app
remotes:
  - key: remote-backend
    baseUrl: https://my-backend-api-url-here.com/
    operations:
      - storage
      - compute
      - fetch
    storage:
      inScopeEUD: true
resources:
  - key: main
    path: src/frontend/index.jsx
  - key: action
    path: src/frontend/action.jsx

So when I set or retrieve my inner API key in jira:issueAction, everything works fine. When I request our API from the jira:issuePanel, everything works fine. But when I want to retrieve API key in jira:issuePanel using invoke from ‘@forge/bridge’ I get

Uncaught (in promise) Error: Invalid response from remote
    at invoke

on global-bridge.js.

I tried changing resolver to function - then I can get the value from the storage but cannot request my API. The idea was to get the api key and add it to a context which is used by functions that request the API.

I also tried requestJira inside those functions as the docs say I can use Jira REST API: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-app-properties/#api-rest-atlassian-connect-1-addons-addonkey-properties-propertykey-get

But It requires addonKey - and I have none since it’s Forge, not Connect app.

Thus:

  • any ideas of how to get storage working for jira:issuePanel with an endpoint as a resolver
    Or
  • maybe you could advise a better way to store API key inside Forge app?

Can you double-check your code. When calling a remote endpoint your should be using invokeRemote instead of the regular invoke.

Thank you for your comment.

I use invokeRemote to call my API.
Tried to use invoke in issuePanel module calling method from the function resolver to get value from storage.
Also tried to call storage.get with Forge runtime not found. error.

If I’m understanding correctly, you’re trying to call both a remote API and also a Forge resolver from the same module? I don’t think that’s currently supported. You have to choose one or the other.

You should be able to query Forge’s storage from a remote endpoint. Have you tried this?

Yes, I tried to use both invoke and invokeRemote in the same module because I want to make a request from Forge app to a remote API using my api key which I’d like to get from Forge’s storage. I do not need to call Jira API from the outside.

@IvanDolgov,

Forge Remote has it’s own auth mechanism, not based on arbitrary API keys.

Forge Fetch allows you to make arbitrary API calls to a registered remote (as confusing as that sounds, fetch is not “Forge Remote”). You may use that with built-in OAuth provider which will perform the authorization code flow. If your API is not based on OAuth, you’ll have to provide fetch with the appropriate headers.

2 Likes

Thank you, so far it seems like an appropriate solution. Thus I can use Storage API to store and retrieve arbitrary keys and Fetch API to request my remote backend.