Connecting Forge app with remote server

Hello :wave:

I’m trying to call remote server api using invokeRemote function from @forge/bridge package but I’m getting the following error:

Error: Resolver has no definition for 'undefined'

Here is my manifest.yml file:

modules:
  jira:issueActivity:
    - key: sastrify-support-app-issue-activity
      resource: activity
      resolver:
        endpoint: remote-jira-endpoint
      render: native
      title: Sastrify Support
  jira:issueContext:
    - key: sastrify-support-app-issue-context
      resource: context
      resolver:
        function: resolver
      render: native
      title: Sastrify Support
      description: Sastrify Support
      label: Sastrify Support
  function:
    - key: resolver
      handler: index.handler
  endpoint:
    - key: remote-jira-endpoint
      remote: remote-jira-service
      auth:
        appUserToken:
          enabled: true
        appSystemToken:
          enabled: true
resources:
  - key: activity
    path: src/frontend/activity/activity.jsx
  - key: context
    path: src/frontend/context/context.jsx
permissions:
  scopes:
    - read:app-system-token
    - read:app-user-token
remotes:
  - key: remote-jira-service
    baseUrl: https://heavily-intimate-urchin.ngrok-free.app
    auth:
      appSystemToken:
        enabled: true
      appUserToken:
        enabled: true
    operations:
      - compute
app:
  runtime:
    name: nodejs20.x

And this is the UI:

import React from 'react';
import ForgeReconciler, { Stack, Text } from '@forge/react';
import { invokeRemote } from "@forge/bridge";
import { Modal } from './components';

const SastrifySupportTab = () => {
  const handleFormSubmission = async (data) => {
    const response = await invokeRemote({
      path: '/jira-integration-service',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });

    console.log(response);
  };

  return (
    <Stack alignInline="center" space="space.0">
      <Text>Test</Text>
      <Modal handleFormSubmission={handleFormSubmission} />
    </Stack>
  );
};

ForgeReconciler.render(
  <React.StrictMode>
    <SastrifySupportTab />
  </React.StrictMode>
);

Welcome to the Atlassian developer community @nikolaradovic,

The first parameter of invokeRemote() must be a valid remoteKey. For this case, that would be remote-jira-service.

@ibuchanan thanks for the reply.

But this invokeRemote from @forge/bridge, which I’m using on the UI, doesn’t accept second argument, at least according to the official documentation.
P.S. Anyway I tried it but didn’t help.

Remote key is required for the invokeRemote from @forge/api which can be used in functions.

Did I get it right? Never have worked with forge before, so maybe I got something wrong.

I stand corrected. Yes, you do seem to have applied the correct invokeRemote() via @forge/bridge. I guess I rushed to conclusion based on the error about undefined.

The only other thing that I can see is that auth.appUserToken and auth.appSystemToken might be mutually exclusive. I can’t find that clearly in the docs, but what the spec says about each suggests to me they might be. In short, you can’t have both auth principals at the same time.

I tried setting them to false, also removing the auth part at all, but nothing’s helped. Btw, I see in this example app that both tokens are set to true.

Hi @nikolaradovic, the code snippet that you attached, is that of activity.jsx or context.jsx?
I can see that you’ve configured your jira:issueActivity module to use your remote endpoint as a resolver, but the jira:issueContext is using a Forge function resolver, so if you are calling invokeRemote from context.jsx, it won’t work.

1 Like

Hi @BoZhang, it’s activity.jsx, the one I configured endpoint for.

Update: Issue solved :white_check_mark:

Since I’m using tunnel for testing, I didn’t know that changing manifest.yml file won’t take place before deploying and installing the newest version of app.
After I did that, I’ve been able to communicate with the remote server.

@ibuchanan @BoZhang thanks for the assistance :raised_hands:

1 Like