Expand my Community achievements bar.

SOLVED

Calling ContentFragment API from Postman works. But same payload from AppBuilder action throws `code: ERR_INVALID_ARG_TYPE`

Avatar

Level 5

I am trying https://adobe-sites.redoc.ly/tag/Fragment-Management#operation/fragments/createFragment CF API to programmatically create content fragments from inside AppBuilder action. I first tried the swagger request from postman and verified the request works. Request looks like this 

curl --location 'https://author-*-*.adobeaemcloud.com/adobe/sites/cf/fragments' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <hidden>' \
--data '{
    "title": "625875",
    "modelId": "L2NvbmYvc2d3cy9jb3JwL3NldHRpbmdzL2RhbS9jZm0vbW9kZWxzL3NhbHNpZnktZnJhZ21lbnQtbW9kZWw",
    "parentPath": "/content/dam/product-content",
    "fields": [{"name":"salsify:ageStatement","values":["Age Statement 625875"],"type":"text"},{"name":"salsify:brandStory","values":["Brand Story 625875"],"type":"text"},{"name":"salsify:tastingNotes","type":"text"}]
  }'

 

Next I hardcoded and generated exact request into an AppBuilder action and invoked it. The request keeps failing with error `{"code":"ERR_INVALID_ARG_TYPE"}`

 

Nothing useful in server log, I dont see any log in server error.log file. 

 

Have anyone tried and faced similar error? Any pointers whats missing can help me. thanks. 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 5

I was able to resolve. So earlier, I used Javascript fetch inside nodejs with async/await syntax. Somehow async await and fetch api was not working good inside AppBuilder Runtime action. 

 

I switched to axios and this time it works perfect. This is sample code I used and is working. 

const axios = require('axios');
let data = JSON.stringify({
  "title": "625875",
  "modelId": "L2NvbmYvc2d3cy9jb3JwL3NldHRpbmdzL2RhbS9jZm0vbW9kZWxzL3NhbHNpZnktZnJhZ21lbnQtbW9kZWw",
  "parentPath": "/content/dam/product-content",
  "fields": [
    {
      "name": "ageStatement",
      "values": [
        "Age Statement 625875"
      ],
      "type": "text"
    },
    {
      "name": "brandStory",
      "values": [
        "Brand Story 625875"
      ],
      "type": "text"
    },
    {
      "name": "tastingNotes",
      "type": "text"
    }
  ]
});

let config = {
  method: 'post',
  url: 'https://author-**-**.adobeaemcloud.com/adobe/sites/cf/fragments',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic **', 
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Here CF supports both BasicAuth and Bearer Token. I tested with both and they work. 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 5

I was able to resolve. So earlier, I used Javascript fetch inside nodejs with async/await syntax. Somehow async await and fetch api was not working good inside AppBuilder Runtime action. 

 

I switched to axios and this time it works perfect. This is sample code I used and is working. 

const axios = require('axios');
let data = JSON.stringify({
  "title": "625875",
  "modelId": "L2NvbmYvc2d3cy9jb3JwL3NldHRpbmdzL2RhbS9jZm0vbW9kZWxzL3NhbHNpZnktZnJhZ21lbnQtbW9kZWw",
  "parentPath": "/content/dam/product-content",
  "fields": [
    {
      "name": "ageStatement",
      "values": [
        "Age Statement 625875"
      ],
      "type": "text"
    },
    {
      "name": "brandStory",
      "values": [
        "Brand Story 625875"
      ],
      "type": "text"
    },
    {
      "name": "tastingNotes",
      "type": "text"
    }
  ]
});

let config = {
  method: 'post',
  url: 'https://author-**-**.adobeaemcloud.com/adobe/sites/cf/fragments',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic **', 
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Here CF supports both BasicAuth and Bearer Token. I tested with both and they work.