credentials are setup using forge Variables and are picked using process.env.CREDENTIALS
issue is indeed created in instance 2 but the statement at line no. 10 is never printed in the logs. Why?
Observation: If I run the event using forge tunnel, then it works perfectly but when I install it in a Jira instance, it does not print line 10! What could be the issue?
I have tried fetch(), api.fetch(), importing fetch from forge library,importing fetch from node-fetch library. I tried calling fetch in a separate function and return it. Also tried fetch().then().
You cannot use fetch against the Atlassian products. You must use the fetch wrappers known as the product fetch API. In the REST API docs, the Fetch example is the default and shows how you should make the request:
@ibuchanan
But I am posting the data to some other instance, not the same jira instance. Can I create a route for another instance? Couldn’t find documentation for that
That is not possible from within Forge. Tenant isolation is a key feature of Forge, so it is intentional that you cannot reach another instance. You would need some kind of external system to perform the cross-instance routing, and then have your own way of using Forge Remote to connect to that system. You didn’t miss anything in the docs; there is no guidance for doing this.
@ibuchanan But it is reaching the 2nd instance. It is successfully creating the issue, but further execution of the code stops after that. What I couldn’t understand is, why doesn’t it continue the execution if fetch is successfully creating the issue in the 2nd instance?
Hi @SachinSaini
Cross tenant requests like this is not a normal use case in Forge, although for your use case I can see that you are using API tokens as authentication and making a standard egress call, which should work in theory.
Here are the things I would check:
How are you validating logs are being emitted? have you tried logging before your call to make sure that the logs are being sent? If not then are the filters correct for your log level in the developer console?
I don’t have full context of the code path, but are promises being awaited properly all the way through?
How are you validating logs are being emitted? have you tried logging before your call to make sure that the logs are being sent? If not then are the filters correct for your log level in the developer console? Ans. : I am adding a log statements before and after the fetch call. Here’s the result in CMD when I am running in a tunnel:
I don’t have full context of the code path, but are promises being awaited properly all the way through? Ans.: Yes, As you can see in the code itself that I posted, I am awaiting fetch call to resolve before printing the debug statement. You can confirm that I am using it correctly because it is working when I run a tunnel.
I also tried using .then(), still does not work.
Yes, As you can see in the code itself that I posted, I am awaiting fetch call to resolve before printing the debug statement. You can confirm that I am using it correctly because it is working when I run a tunnel.
Promises may behave different between the running things locally through the tunnel and within the Forge function. If you do not await promises all the way through, the Forge function might finish earlier than you expect and some code that you expect to run will not run. Are you able to share the code that calls the code snippet that you provided?
I know that async functions should usually await for response, but if it has only a single statement, it should run because it has a separate execution context. Something is different in forge. Where do I get more information on how it works in the backend?