Can the firefly project access AEM Assets api? | Community
Skip to main content
October 18, 2021
Solved

Can the firefly project access AEM Assets api?

  • October 18, 2021
  • 2 replies
  • 2510 views

Hi all,
    I have one investigation requirement to check if there is a way to access Assets api from Jira or other external projects. When I am looking into firefly project, it looks like it is feasible. But, I cannot find any useful docs. Any suggestions?
    Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by shelly-goel

Yes Assets API can be used in App Builder.

An example action snippet for folder creation below:

const token = getBearerToken(params);
apiEndpoint = `${aemEndpoint.value}/api/assets/${params.folderPath}`;
      const raw = JSON.stringify({
        class: 'assetFolder',
        properties: {
          'jcr:title': `${params.folderTitle}`,
        },
      });
      res = await fetch(apiEndpoint, {
        method: 'post',
        headers: {
          Authorization: `Bearer ${token}`,
          'Content-Type': 'application/json',
        },
        body: raw,
      });
 
token generation code snippet:
function getBearerToken(params) {
  const { __ow_headers: OwHeaders = {} } = params;

  if (
    OwHeaders &&
    OwHeaders.authorization &&
    OwHeaders.authorization.startsWith('Bearer ')
  ) {
    return OwHeaders.authorization.substring('Bearer '.length);
  }
  return undefined;
}

2 replies

Adobe Employee
October 18, 2021

I am not fullu clear on what your requirements are for your use case but yes App Builder/Project Firefly can call the AEM Assets API.  This is of course if the AEM instance is hosted on the public internet and the api end point is not protected by a firewall. I have written actions in the past that used the Assets API and it was pretty straight forward to do.

 

Project Firefly/App Builder Actions are built using standard nodejs and nodejs has the fetch library for making POST/GET/PATCH/DELETE Rest calls.

 

I don't see any code labs or medium articles that publish code out there.  We are working on more AEM use case sample code as we speak.

shelly-goel
Adobe Employee
shelly-goelAdobe EmployeeAccepted solution
Adobe Employee
October 19, 2021

Yes Assets API can be used in App Builder.

An example action snippet for folder creation below:

const token = getBearerToken(params);
apiEndpoint = `${aemEndpoint.value}/api/assets/${params.folderPath}`;
      const raw = JSON.stringify({
        class: 'assetFolder',
        properties: {
          'jcr:title': `${params.folderTitle}`,
        },
      });
      res = await fetch(apiEndpoint, {
        method: 'post',
        headers: {
          Authorization: `Bearer ${token}`,
          'Content-Type': 'application/json',
        },
        body: raw,
      });
 
token generation code snippet:
function getBearerToken(params) {
  const { __ow_headers: OwHeaders = {} } = params;

  if (
    OwHeaders &&
    OwHeaders.authorization &&
    OwHeaders.authorization.startsWith('Bearer ')
  ) {
    return OwHeaders.authorization.substring('Bearer '.length);
  }
  return undefined;
}
HuiDeShaoAuthor
October 19, 2021

@shelly-goelThanks for your sample!
One more "**bleep**" question 😂, to be honest, I'm pretty beginner to AEM, so how to find the AEM API endpoint, please?
Now, I can access my company's Assets tool via url like "https://xxx.experiencecloud.adobe.com/assets.html/content/dam/mac/xxx". I tried to access url like "https://xxx.experiencecloud.adobe.com/api/assets", but it didn't work...

HuiDeShaoAuthor
October 19, 2021

I think I find some info from https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/developing/generating-access-tokens-for-server-side-apis.html#developer-flow.
It looks like Company's AEM instance is manged in cloud manager. I don't have right access to login some env like "https://author-xxx-xxx.adobeaemcloud.com". When trying to "Get local development token", I am getting 403 error. Not sure why.
I will continue to do the deeper investigation.
Thanks all.