Call Jira from an async event handler

Hello team,
I am trying to call Jira’s REST API from an async event handler. However the call is failing because the async event handler’s context of execution is apparently not authenticated. Can you help me resolve this issue ?

resolver.define('event', async ({ payload, context }) => {
  const project = payload.context.extension.project;
  const boardsForProject = await getDataFromJira(
    `/rest/agile/1.0/board?projectKeyOrId=${project.key}`
  );

});

Thanks!
Zak Benbakkar

Hi Zak,

What does the getDataFromJira function do and what is the error message you are seeing?

Hi Alexey,
Good question! getDataFromJira calls api.asUser().requestJira().
The response I got was a 401

[NEEDS_AUTHENTICATION_ERR: Authentication required] {
  serviceKey: 'atlassian-token-service-key',
  status: 401
}

I just realised that api.asUser().requestJira() fires a request without the authorisation header. For instance api.asApp().requestJira() works out of the box.
Thanks anyway!