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
BedrockMission!

Learn More

View all

Sign in to view all badges

Using Assets Http APIs in Postman or through React Code

Avatar

Avatar
Give Back 10
MVP
shelly-goel
MVP

Likes

180 likes

Total Posts

337 posts

Correct Reply

88 solutions
Top badges earned
Give Back 10
Validate 1
Shape 1
Ignite 1
Give Back 5
View profile

Avatar
Give Back 10
MVP
shelly-goel
MVP

Likes

180 likes

Total Posts

337 posts

Correct Reply

88 solutions
Top badges earned
Give Back 10
Validate 1
Shape 1
Ignite 1
Give Back 5
View profile
shelly-goel
MVP

19-05-2021

Please suggest how can we leverage Assets Http API in react code.

1. I'm trying to convert "Create a folder" request into react code, how will the below request map into the code. I can understand Content-Type: application/json will go in headers. What does -d map to in the code?

  • POST /api/assets/myFolder -H"Content-Type: application/json" -d '{"class":"assetFolder","properties":{"title":"My Folder"}}'

https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/mac-api-assets.html?l...

 

2. How do we access these API in postman (other than curl)? Now AEM is on cloud so cannot use admin credentials and on using generic user credentials as Basic Auth, I'm getting 401 Unauthorized.

3. I'm able to run GET request in browser, how to do POST request of these APIs in postman.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

511 likes

Total Posts

647 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

511 likes

Total Posts

647 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

19-05-2021

Hi @shelly-goel,

Please find my comments inline in green

1. I'm trying to convert "Create a folder" request into react code, how will the below request map into the code. I can understand Content-Type: application/json will go in headers. What does -d map to in the code?

  • -d indicates the data input for the POST request - To be part of request body while calling API.

2. How do we access these API in postman (other than curl)? Now AEM is on cloud so cannot use admin credentials and on using generic user credentials as Basic Auth, I'm getting 401 Unauthorized.

3. I'm able to run GET request in browser, how to do POST request of these APIs in postman.

  • Since we are accessing API call hosted from Cloud Instance, we can use Bearer Authorization Type with token value as input (Not a Basic Authorization type that we would do with local AEM instance or Cloud Service SDK local instance)
  • Raw input with JSON as input with respective Content-Type Header
    {
                    class: 'assetFolder',
                    properties: {"title":"New Folder"}
    }

Sample Application in above doc illustrates the folders listing and update metadata. Below is the similar call for "Create Folder" request that you can use in React component.

 

 // The root context of the Assets HTTP API
const ASSETS_HTTP_API = '/api/assets';
const NEW_FOLDER_TO_CREATE = '/myFolder';

 await fetch(`${params.aem}${ASSETS_HTTP_API}${NEW_FOLDER_TO_CREATE}`, {
            method: 'post',
            headers: { 
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + params.accessToken // Provide the AEM access token in the Authorization header
            },
            body: JSON.stringify({
                class: 'assetFolder',
                properties: {
                    "title": "New Folder"
                }
            })
        })
        .then(res => { 
            console.log(`${res.status} - ${res.statusText}`);
        });

 

 Outside this, please do let know on what action/scenario(Eg. on load of a component or on any other CTA)you are expecting to trigger "Create Folder" call, we can decide on where to use fetch call accordingly from React component Standpoint. 

Answers (1)

Answers (1)

Avatar

Avatar
Boost 5
Level 5
Ritesh_M
Level 5

Likes

101 likes

Total Posts

85 posts

Correct Reply

26 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 5
Ritesh_M
Level 5

Likes

101 likes

Total Posts

85 posts

Correct Reply

26 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 5

19-05-2021

Hi @shelly-goel ,

 

You can watch the below videos to understand how can we use postman/React to trigger API. To resolve unauthorized user issue I believe you can use system user (user should have privileges assigned) to get resource resolver from sub service, 

 

Using Postman 

Hit API from react component