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.
- Try to use Bearer Authorization Type with token value being the Local Development Access Token that you can get from Cloud instance Developer console.
- For the actual integration, we need to make use of Service Credentials, steps for which is documented in below link with same sample application.
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.