Hi,
Is there any way to know the plugin ID from inside the running code?
Thank you in advance.
Additional Context (2023/06/13)
In my powerup, I am trying to scan the plugin data of all members on a board. Rest API returns the plugin data but it includes multiple instances from different powerups (plugins) installed in the board. So I need to know the plugin ID to select the correct instance.
I know that I can get the plugin ID statically from Trello’s admin page. But I have two powerups with the same code, one for production and the other one for testing. So I want to get the plugin ID dynamically inside the running code.
1 Like
Hi there,
to get the Id of the App for Navigating between App Pages, i use the Product Context “localId”
And get the RefId which sits between “extension/” and “/static”.
import { useProductContext } from '@forge/ui';
function getRefId() {
const context = useProductContext();
const id = context.localId;
const startIndex = id.indexOf('extension/') + 10; // Add 10 to exclude 'extension/'
const endIndex = id.indexOf('/static');
const refId = id.substring(startIndex, endIndex);
return refId;
}
Regards,
Adrian
Hi Adrian,
Thank you for the reply.
I tried it, but I got an exception when calling useProductContext() in my React function component.
I don’t have knowledge about Forge, but it is a different product from Trello. Would the solution you provided also be applicable to Trello PowerUp?
Regards,
Tateo
Oh, I’m sorry. I think this was a mistake on my end. I thought I filtered all Topics regarding “Forge”. I just now see this is “Trello”.
Unfortunately, I have no experience developing for Trello.
Regards,
Adrian
I see 
Anyway, thank you for your reply.
Regards,
Tateo
You can use the t.jwt method which contains the idPlugin - you’ll have to decode it of course. I’m assuming that this is happening on the backend.
An alternative is to just hardcode it. Since you know the plugin IDs of both your test and production Power-Ups (which is unlikely going to change), why not just have it as a constant and do an if-else conditional?
1 Like
Hi,
Thank you for the reply.
It worked! My code runs purely in a browser, so it may not be the intended usage of JWT, but it seems viable.
why not just have it as a constant and do an if-else conditional?
Yeah, it can be a solution
. My initial implementation was to read plugin IDs from .env file and switch them based on a flag imposed in a build script.
The risk of that implementation is that only after I deploy the production code would I know that the ID is mistyped or the switching code has a bug. In my long history, I experienced such horrifying moments … 
I found that the context data returned by t.getContext() includes the plugin ID.
However, it is not documented.
Could someone from the Trello team confirm if I can use the context to extract the plugin ID?
Regards,
Tateo