Hi Team,
I need to raise a request with form data in Request.json
unable to send formdata to request post method throws error
model.js:
let formData = new FormData();
formData.append("requested_for", apiData.requested_for);
formData.append("email", apiData.email);
let jsonObject = {};
formData.forEach((value, key) => {
jsonObject[key] = value;
});
console.log("jsonObject :", jsonObject)
let createTicketRes = await client.request.invokeTemplate("createTicket",{ "context": { "requestItemID": requestItemID,"formData":formData}})
Request.json:
"createTicket": {
"schema": {
"protocol": "https",
"method": "POST",
"host": "<%= iparam.lightHouseUrl %>",
"path": "/api/v2/service_catalog/items/<%= context.requestItemID %>",
"headers": {
"Authorization": "Basic <%= iparam.lightHouseTokenValue %>",
"Content-Type": "application/json",
"formData":"<%= context.formData %>"
},
}
}```
how to convert context.formData to actual formdata in request.json?
is there any workaround?
**Note** : whereas formdata contains attachments also
ERROR`RES:: DOMException: Failed to execute 'postMessage' on 'MessagePort': FormData object could not be cloned.
at obj.postMessage (https://cdn.freshdev.io/assets/app-client@2.js:6:4992)
at https://cdn.freshdev.io/assets/app-client@2.js:6:4939
at new Promise (<anonymous>)
at obj.handleRequest (https://cdn.freshdev.io/assets/app-client@2.js:6:4850)
at obj.invokeTemplate (https://cdn.freshdev.io/assets/app-client@2.js:6:22096)
at formSubmitData (http://localhost:10001/iframe/agent/model.js:10317:73)`
The form-data is not a documented feature. It might have worked in the Request Method before platform v2.3. With platform v2.3, the Request Method has been enhanced to support only via defined request templates. Form-data is not one of the supported options.
If we have to support form-data, we have to accept it as a new feature request and validate and support it if feasible and prioritized.
Multipart content type is not supported, and attachments cannot be sent via Request Template. So, please find alternative way to work with attachments.
Refer to this post for the supported content types in the Request Method.
ERROR MESSAGE
data: {
message: ‘POST method is not allowed. It should be one of these method(s): GET, HEAD’
}
}
TypeError: Converting circular structure to JSON
→ starting at object with constructor ‘ClientRequest’
| property ‘socket’ → object with constructor ‘TLSSocket’
— property ‘_httpMessage’ closes the circle
at JSON.stringify ()
at Object.createTickets (server.js:4480:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
undefined
@Deiviya_Sivacoumar Only GET method is available for Service Item API in Freshservice. I can’t find POST method availability in the documentation.
If it’s an undocumented feature, you would have to check with the Freshservice team to see if it will work as expected. Please create a support ticket for Freshservice to check this.
The first error comes from the API made using Axios.
The second error results from some object being converted into JSON, which has a circular dependency. Please check the same on your code.