Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Can the firefly project access AEM Assets api?

Hugh_Shao
Level 3
Level 3

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.

1 Accepted Solution
shelly-goel
Correct answer by
Community Advisor
Community Advisor

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;
}

View solution in original post

6 Replies
dr_venture
Employee
Employee

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
Correct answer by
Community Advisor
Community Advisor

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;
}

View solution in original post

Hugh_Shao
Level 3
Level 3

@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...

Hugh_Shao
Level 3
Level 3

I think I find some info from https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/developing/gen....
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.

StephanAdobe
Employee
Employee

This sample app shows how to connect to AEM to retrieve and display Assets including thumbnails in a custom UI: 
https://github.com/AdobeDocs/adobeio-samples-aemaacs-assets-custom-ui 

You'll require a running AEMaaCS author instance to test it. Also, it will only run inside the Experience Cloud Shell at experience.adobe.com.  

Hugh_Shao
Level 3
Level 3

Cool, thanks. I will look into this sample later. Now, I am checking how to get the access to my company's author instances. 😂