Do ACC API support multipart/form-data creation? | Community
Skip to main content
Level 2
September 9, 2022
Solved

Do ACC API support multipart/form-data creation?

  • September 9, 2022
  • 2 replies
  • 1851 views

Hello Expert,

I'm developing the javascript to call the Web-service. However, they require the media-type as 'multipart/form-data'.

I've checked this link about ACC API -> https://experienceleague.adobe.com/developer/campaign-api/api/p-8.html

But it's look like, ACC don't have any class that support to create multipart/form-data

I'm not sure that Adobe Campaign Classic v7 can form this type of data? Or can we import the form-data library into ACC -> How to?

Please help.

Thank you.

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 Tobias_Lohmann

Hi,

I'm not sure I'm getting what you're trying to achieve. Do you want to call a remote webservice with ACC and that remote webservice requires multipart/form-data?

In Campaign you can use the HttpClientRequest class to construct your http call (including the Content-Type header as multipart/form-data) and send it to the webservice: https://experienceleague.adobe.com/developer/campaign-api/api/c-HttpClientRequest.html?hl=httpclientrequest 

Best regards, Tobias

2 replies

Tobias_Lohmann
Adobe Employee
Tobias_LohmannAdobe EmployeeAccepted solution
Adobe Employee
September 9, 2022

Hi,

I'm not sure I'm getting what you're trying to achieve. Do you want to call a remote webservice with ACC and that remote webservice requires multipart/form-data?

In Campaign you can use the HttpClientRequest class to construct your http call (including the Content-Type header as multipart/form-data) and send it to the webservice: https://experienceleague.adobe.com/developer/campaign-api/api/c-HttpClientRequest.html?hl=httpclientrequest 

Best regards, Tobias

Level 2
September 12, 2022

Hi Tobias,

I'm trying to do as your said by use HttpClientRequest with header-type as multipart/form-data.

And create a form-data format by following this link

https://stackoverflow.com/questions/47080869/how-to-manually-create-multipart-form-data

Remark: Unfortunately, this link is not verify as accept solution but I think it should be fine.

 

I try to call again via HttpClientRequest but the destination throw 422 'Unprocessable Entity' back.

May be this way we need to change from HttpClientRequest to XMLHttpRequest.

However, XMLHttpRequest is not available in ACC as well.

 

Do you have any workaround for this?

Thank you.

Tobias_Lohmann
Adobe Employee
Adobe Employee
September 13, 2022

Hi,

not a 100% sure, but it might not be possible at all using Campaign's Javascript engine. Are we talking about an on premise installation of Campaign? If yes, you could try to utilize curl 

curl -v -F key1=value1 -F upload=@localfilename URL

This would offload the task to the os level.

Best regards, Tobias

New Member
December 19, 2024

Hi. I managed to solve the problem using the js below.  In my circumstance I was trying to transfer a very simple csv file with a single column with column header that I had already exported to the Adobe server in the previous step.

 

logInfo("File name is: " + vars.filename)
memBuf = new MemoryBuffer()
memBuf.load(vars.filename)
data = memBuf.toString()
logInfo("Size is " + memBuf.size)

boundary = "nVenJ7H4puv"

body = "--" + boundary + '\r\n'
body = body + "Content-Disposition: form-data; name='upFile'; \r\n"
body = body + "Content-Type: text/csv\r\n\r\n" //two carriage returns required before adding the data
body = body + data + '\r\n'
body = body + "--" + boundary + "--\r\n"

 

url ="https://<url of site> "

var http=new HttpClientRequest(url);
http.header ["Content-Type"] = "multipart/form-data; boundary=" + boundary;
http.header ["Accept"] = "*/*";
http.header ["Authorization"] = "whatever";
http.method = "POST" ;
http.body = body;

http.execute();
var result = http.response.body.toString();
logInfo("Result String: "+result);
var responseCode = http.response.code
logInfo("Response code is: "+ responseCode)