Calling ContentFragment API from Postman works. But same payload from AppBuilder action throws `code: ERR_INVALID_ARG_TYPE` | Community
Skip to main content
sarav_prakash
Community Advisor
Community Advisor
August 9, 2024
Solved

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

  • August 9, 2024
  • 1 reply
  • 610 views

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. 

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 sarav_prakash

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. 

1 reply

sarav_prakash
Community Advisor
sarav_prakashCommunity AdvisorAuthorAccepted solution
Community Advisor
August 15, 2024

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.