Rest Api "multipart/form-data"

Rest Api "multipart/form-data"

  
Hi,

How can I convert this content to outsystems rest api

Accept: application/json

Content-Type: multipart/form-data; boundary=AAA

 

--AAA

Content-Type: application/json

Content-Disposition: form-data

{

  "status":"sent",

  "emailBlurb":"Test Email Body",

  "emailSubject": "Test Email Subject - EnvelopeDefFull",

  "documents": [{

      "name": "test1.pdf",

      "documentId":"1",

      "order":"1"

  }],

  "recipients": {

    "signers" : [{

      "email": "m.rosey@thomasind.com ",

      "name": "Mike Rosey",

      "recipientId":"1",

    }]

  }

}

--AAA

Content-Type: application/pdf

Content-Disposition: file; filename="test1.pdf";documentid=1

 

<documents removed>

 

--AAA--

You need to have a single definition, so include the PDF into the form data.
Hi Ozkan,

There are some examples like that in the forge. Try checking the Box or the Dropbox components, pretty sure one of them need it as well.
Multipart requests are not out-of-the-box, they need to be done using the OnBeforeRequest or OnBeforeRequestAdvanced callbacks to change the body binary directly.

Regards,
João Rosado

I had this exact question and found the example João Rosado mentioned in the Box connector (http://www.outsystems.com/forge/component/586/box-connector/).

This connector's FileUpload method can be copied and adapted for other multipart/form-data scenarios.

Sorry guys, I am opening old thread but I am facing same problem with upload file.

I have REST API like this

POST /rest/bfo/mycase/2.0/cases

Authorization: Bearer 6f0aab651234e57b4ba4567da3f47a

Content-Type: multipart/form-data; boundary="boundary_string"

X-SE-IFW-BFOAccessToken: 00D17000000A1E7!ARwAQAp0ALjoR_.X6Q9GVFcHUxOxWkT0cGvZnTnzNISZMbzihsFyWWxTCYmzSEhxplVviv8j0dQpY.jCa2aFxBRNpZ67M3Gf

X-SE-IFW-ApplicationName: CCCAPP

X-SE-IFW-CountryCode: FR

X-SE-IFW-LanguageCode: EN

X-SE-IFW-RequestId: 10001

--boundary_string

Content-Disposition: form-data; name="entity_document";

Content-Type: application/json

{
 "portalId": "Meter Insights",
 "sendAutoGeneratedEmail": "false",
 "caseInformation": {

      "accountId": "0011100001OfIAeAAN",
 "subject": "RegisterCaseTesting",
 "customerRequest": "Testing",
 "category": "Pricing and Availability",
 "reason": "Comments",
 "severity": "Normal",
 "status": "New",
 "priority": "Normal",
 "origin": "Phone",
 "type": "Feature Request",
 "CCTeam": "CCC-MobileApp",
 "CCCountryCode": "FR",
 "callBackNumber": "7410258963",
 "productReference": "Prod133",
 "materialDescription": "MD0032",
 "symptom": "working"
 },
 "caseOwner": [
 "SESA56238"
 ],
 "webInformation": {
 "name": "saleha",
 "emailAddress": "saleha_saheen@thbs.com",
 "phone": "9945678432",
 "company": "Thbs",
 "country": "Japan",
 "language": "Japanese",
 "jobTitle": "Software Engineer"
 },
 "additionalDetails": {
 "quantity": "1.0",
 "serialNumbers": "1234",
 "dateCodes": "20151212",
 "operatingSystem": "Windows8",
 "softwareVersion": "1.0"
 }
 }

--boundary_string

Content-Type: text/plain

Content-Disposition: form-data; name="Body"; filename="api-test.txt"

Binary data of the file goes here

--boundary_string--

Can you help me how should I implement this. 

@Joao, I tried that action from FileUpload but I am unable to do it. Can you please write one action for me to consume this API.

Thanks and Regards,

Suraj Borade

Suraj Borade wrote:

Sorry guys, I am opening old thread but I am facing same problem with upload file.

I have REST API like this

POST /rest/bfo/mycase/2.0/cases

Authorization: Bearer 6f0aab651234e57b4ba4567da3f47a

Content-Type: multipart/form-data; boundary="boundary_string"

X-SE-IFW-BFOAccessToken: 00D17000000A1E7!ARwAQAp0ALjoR_.X6Q9GVFcHUxOxWkT0cGvZnTnzNISZMbzihsFyWWxTCYmzSEhxplVviv8j0dQpY.jCa2aFxBRNpZ67M3Gf

X-SE-IFW-ApplicationName: CCCAPP

X-SE-IFW-CountryCode: FR

X-SE-IFW-LanguageCode: EN

X-SE-IFW-RequestId: 10001

--boundary_string

Content-Disposition: form-data; name="entity_document";

Content-Type: application/json

{
 "portalId": "Meter Insights",
 "sendAutoGeneratedEmail": "false",
 "caseInformation": {

      "accountId": "0011100001OfIAeAAN",
 "subject": "RegisterCaseTesting",
 "customerRequest": "Testing",
 "category": "Pricing and Availability",
 "reason": "Comments",
 "severity": "Normal",
 "status": "New",
 "priority": "Normal",
 "origin": "Phone",
 "type": "Feature Request",
 "CCTeam": "CCC-MobileApp",
 "CCCountryCode": "FR",
 "callBackNumber": "7410258963",
 "productReference": "Prod133",
 "materialDescription": "MD0032",
 "symptom": "working"
 },
 "caseOwner": [
 "SESA56238"
 ],
 "webInformation": {
 "name": "saleha",
 "emailAddress": "saleha_saheen@thbs.com",
 "phone": "9945678432",
 "company": "Thbs",
 "country": "Japan",
 "language": "Japanese",
 "jobTitle": "Software Engineer"
 },
 "additionalDetails": {
 "quantity": "1.0",
 "serialNumbers": "1234",
 "dateCodes": "20151212",
 "operatingSystem": "Windows8",
 "softwareVersion": "1.0"
 }
 }

--boundary_string

Content-Type: text/plain

Content-Disposition: form-data; name="Body"; filename="api-test.txt"

Binary data of the file goes here

--boundary_string--

Can you help me how should I implement this. 

@Joao, I tried that action from FileUpload but I am unable to do it. Can you please write one action for me to consume this API.

Thanks and Regards,

Suraj Borade

Have you already solved this Suraj? I'm also having trouble consuming a POST service using "multipart/form-data".


Hi guys.

It's possible to build a multipart/form-data request by constructing the binary payload by hand. I saw this being done in some components such as the Asana Connector for uploading attachments to Asana tasks. Download it and inspect the code to see how to invoke such a service.

Hi Jasper,

I solved my problem. Let me know how your request looks like and I can try to give you the solution.

Thanks and Regards,

Suraj Borade

Hi Suraj,

Perhaps you can take a look at this topic, someone's having the same problem.

Suraj Borade wrote:

Hi Jasper,

I solved my problem. Let me know how your request looks like and I can try to give you the solution.

Thanks and Regards,

Suraj Borade

Hi Suraj,

This is the AJAX export from a working POSTMAN example I'm trying to get to work in OutSystems:

var form = new FormData();
form.append("options", "{\"period\":\"12\"}");
form.append("texts", "1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://sandbox.api.sap.com/ml/timeseriesforecast/inference_sync",
  "method": "POST",
  "headers": {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
    "APIKey": "<<APIKey>>",
    "Cache-Control": "no-cache",
    "Postman-Token": "6c8d62d3-5f9f-6e35-3540-8bea752ea560"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

Hope you have a solution for this in OutSystems.

@Kilian sir,

That guy is from my company only and I am the one who has given him the code to consume that web service. I will debug his code to check what he is doing wrong.

@Jasper: I will try to check with this info provided but if you can provide request payload from API documentation that would be helpful.

@Suraj thanks!

Hi Jasper,

I tried consuming that but it's giving me an invalid API Key error. If you don't mind, can you please share the API Key so that I can test properly.

If that is not possible, from postman send me Http export code generated instead of ajax export code.

Thanks and Regards,

Suraj Borade

Suraj Borade wrote:

Hi Jasper,

I tried consuming that but it's giving me an invalid API Key error. If you don't mind, can you please share the API Key so that I can test properly.

If that is not possible, from postman send me Http export code generated instead of ajax export code.

Thanks and Regards,

Suraj Borade

Hi Suraj,

Sorry, I can not give you the APIKey because it's connected to my personal account at SAP Leonardo Machine Learning services. But below is the HTTP export of Postman, thanks in advance!!!


POST /ml/timeseriesforecast/inference_sync HTTP/1.1
Host: sandbox.api.sap.com
Accept: application/json
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
APIKey: <<apikey>>
Cache-Control: no-cache
Postman-Token: 97a334ee-bfa4-2716-8a5e-2cd80cc58499

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="options"

{"period":"12"}
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="texts"

1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"

{{files}}
------WebKitFormBoundary7MA4YWxkTrZu0gW--


Hi Jasper,

Really sorry for the late reply. I was stuck in other problems.

PFA oml for the http request shown above. 

On page ConsumeAPI there's one action and I have added the code there with comments. Try with this and let me know if you are able to consume it.

If you want to discuss, we can have a quick skype call.

Cheers!!

Suraj Borade

Hi Suraj,

I'm also late with my reply :)
Many thanks! I'm going to test it in this evening! Will let you know if it worked for me!

Regards,

Jasper

Suraj Borade wrote:

@Kilian sir,

That guy is from my company only and I am the one who has given him the code to consume that web service. I will debug his code to check what he is doing wrong.

@Jasper: I will try to check with this info provided but if you can provide request payload from API documentation that would be helpful.

Hi Suraj,

Can you please create a sample for multipart data it will be helpful for us.

Regards

-SK-


Hello,


For those who may be still facing this issue: I've published a Forge component which helps submitting multipart/form-data content.

https://www.outsystems.com/forge/component/3731/multipart-upload/


Thanks.