hemi345
02/04/2025, 2:39 PMThis API request must have its Content-Type set to multipart/form-data.
curl -v -u api_key:X -F 'attachments[]=@/Users/user/Desktop/api2.png' -F 'priority=2' -X PUT '<https://domain.freshservice.com/api/v2/tickets/51>'
but when I try the following,
cfhttp(url="#fsURL#",method="PUT",result="fsResult") {
cfhttpparam(type="header",name="Authorization",value="Basic #fsAuthorization#");
cfhttpparam(type="header",name="Content-Type",value="multipart/form-data");
cfhttpparam(type="file",name="attachments[]",file='e:\fsApi\attachments\#childData.ticket_id#\test.jpg');
}
I get the following error:
{"message":"Invalid request parameters: invalid %-encoding (����\"#Exif\u0000\u0000II*\u0000\b\u0000\u0000\u0000\u000B\u0000\u000F\u0001\u0002\u0000\u0014\u0000\u0...\u0019\u001A%)","code":"invalid_encoding"}
If I add priority, then I don't get an error, priority does get set to 2, but the attachment never gets added:
cfhttp(url="#fsURL#",method="PUT",result="fsResult") {
cfhttpparam(type="header",name="Authorization",value="Basic #fsAuthorization#");
cfhttpparam(type="header",name="Content-Type",value="multipart/form-data");
cfhttpparam(type="formfield",name="priority",value="2");
cfhttpparam(type="file",name="attachments[]",file='e:\fsApi\attachments\#childData.ticket_id#\test.jpg');
//cfhttpparam(type="file",name="test.jpg",file='e:\fsApi\attachments\#childData.ticket_id#\test.jpg');
}
I tried the commented out line above too and still no error and no attachment.hemi345
02/04/2025, 2:43 PMcfhttp(url="#fsURL#",method="#fsMethod#",result="fsResult",getasbinary="yes") {
cfhttpparam(name="Content-Type",type="header",value="application/json");
cfhttpparam(name="Authorization",type="header",value="Basic #fsAuthorization#");
}
jsteinshouer
02/04/2025, 2:50 PMmultipart="yes"
to the cfhttp call. I have had issues mixing formfield and file in the same request with ACF. Maybe a bug?jsteinshouer
02/04/2025, 2:59 PMjsteinshouer
02/04/2025, 3:00 PMvar requestBody = [];
var fieldBoundary = "--------------" & getTickCount();
requestBody.append("#NEW_LINE##NEW_LINE#--#fieldBoundary##NEW_LINE#");
requestBody.append("Content-Disposition: form-data; name=""importRequest""#NEW_LINE#");
requestBody.append("Content-Type: application/json#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( serializeJSON( myJSONData ) );
requestBody.append("#NEW_LINE#--#fieldBoundary##NEW_LINE#");
requestBody.append("Content-Disposition: form-data; name=""attachments[]""; filename=""#file.getFormattedName()#.csv""#NEW_LINE#");
requestBody.append("Content-Type: text/csv#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( fileRead('e:\fsApi\attachments\#childData.ticket_id#\test.jpg', "utf-8") );
requestBody.append("#NEW_LINE#--#fieldBoundary#--#NEW_LINE#");
var requestParameters = [
{ type: "header", name: "Content-Type", value: "multipart/form-data; boundary=#fieldBoundary#" },
{ type: "body", value: requestBody.toList( "" ) }
];
cfhttp(
method=fsMethod,
charset="utf-8",
url=fsURL,
result="httpResponse"
) {
for ( var httpParameter in httpParameters ) {
cfhttpparam( attributeCollection = httpParameter );
}
}
jsteinshouer
02/04/2025, 3:01 PMrequestBody.append( serializeJSON( myJSONData ) );
You would need to put in the form field data.hemi345
02/04/2025, 3:05 PMhemi345
02/04/2025, 3:07 PMquetwo
02/04/2025, 3:15 PMjsteinshouer
02/04/2025, 3:25 PM```
var NEW_LINE = chr(13) & chr(10);
var requestBody = [];
var fieldBoundary = "--------------" & getTickCount();
requestBody.append("#NEW_LINE##NEW_LINE#--#fieldBoundary##NEW_LINE#");
requestBody.append("Content-Disposition: form-data#NEW_LINE#");
requestBody.append("Content-Type: application/x-www-form-urlencoded#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( "priority=2" );
requestBody.append("#NEW_LINE#--#fieldBoundary##NEW_LINE#");
requestBody.append("Content-Disposition: form-data; name=""attachments[]""; filename=""#file.getFormattedName()#.csv""#NEW_LINE#");
requestBody.append("Content-Type: text/csv#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( fileRead('e:\fsApi\attachments\#childData.ticket_id#\test.jpg', "utf-8") );
requestBody.append("#NEW_LINE#--#fieldBoundary#--#NEW_LINE#");
var requestParameters = [
{ type: "header", name: "Authorization", value: "Basic #fsAuthorization#" },
{ type: "header", name: "Content-Type", value: "multipart/form-data; boundary=#fieldBoundary#" },
{ type: "body", value: requestBody.toList( "" ) }
];
cfhttp(
method=fsMethod,
charset="utf-8",
url=fsURL,
result="httpResponse"
) {
for ( var httpParameter in httpParameters ) {
cfhttpparam( attributeCollection = httpParameter );
}
}
```
jsteinshouer
02/04/2025, 3:33 PMhemi345
02/04/2025, 3:46 PMjsteinshouer
02/04/2025, 3:50 PMcontent = isBinary(gethttprequestdata().content ) ? CharsetEncode(gethttprequestdata().content, "UTF-8") : gethttprequestdata().content ;
writeOutput("<pre>#content#</pre>");abort;
jsteinshouer
02/04/2025, 3:52 PMhemi345
02/04/2025, 4:01 PMjsteinshouer
02/04/2025, 4:03 PMjsteinshouer
02/04/2025, 4:09 PMhemi345
02/04/2025, 4:22 PMhemi345
02/04/2025, 4:25 PMhemi345
02/04/2025, 4:26 PMjsteinshouer
02/04/2025, 4:27 PMhemi345
02/04/2025, 4:35 PMhemi345
02/04/2025, 7:20 PMjsteinshouer
02/04/2025, 7:25 PMrequestBody.append("Content-Type: text/csv#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( fileRead('e:\fsApi\attachments\#childData.ticket_id#\test.jpg', "utf-8") );
jsteinshouer
02/04/2025, 7:25 PMrequestBody.append("Content-Type: image/jpeg#NEW_LINE#");
requestBody.append(NEW_LINE);
requestBody.append( filereadbinary('e:\fsApi\attachments\#childData.ticket_id#\test.jpg', "utf-8") );
hemi345
02/04/2025, 7:25 PMhemi345
02/04/2025, 7:26 PMhemi345
02/04/2025, 7:27 PMrequestBody.append('Content-Disposition: form-data; name="attachments[]"; filename="#filen#"#NEW_LINE#');
requestBody.append('Content-Type: #fileGetMimeType("e:\fsApi\attachments\#fsTicketId#\#filen#")##NEW_LINE#');
requestBody.append(NEW_LINE);
requestBody.append(fileRead('e:\fsApi\attachments\#fsTicketId#\#filen#'));
hemi345
02/04/2025, 7:28 PMhemi345
02/04/2025, 7:30 PMhemi345
02/04/2025, 7:33 PMhemi345
02/04/2025, 7:34 PMhemi345
02/04/2025, 7:36 PMhemi345
02/04/2025, 7:36 PMjsteinshouer
02/04/2025, 7:53 PMhemi345
02/04/2025, 7:53 PMquetwo
02/05/2025, 4:09 AMhemi345
02/05/2025, 7:07 PM{
"message": "Invalid request parameters: invalid %-encoding ('' id='W5M0MpC...) , #)",
"code": "invalid_encoding"
}
Not encouraging. I'm reaching out to Freshservice to see what they have to say.