File in the form-data Body of a CreationAccount operation in WebServices

Which IIQ version are you inquiring about?

Version 8.3

Share all details related to your problem, including any error messages you may have received.

Hello community. I’m triying to create an account in a webservices connector. In previous tests in postman, the body of this request must contain a file (form-data = file) for it to work correctly . The issue is that I don’t know if its possible to change the body form-data so that a file can be added as I did in postman instead of this default schema of key-value.
Thank you in advance.

Hi @jmolinav

In this case, you can use an AfterOperationRule to execute the following code:

<Rule name="Example Rule" type="WebServiceAfterOperationRule">
  <Description>This rule is used by the  Web Services connector before performing any operation like testconnection, aggregation etc.</Description>
  <Source><![CDATA[

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClients;

import java.io.File;
import java.io.IOException;

String url = "https://example.com/webservice";

String filePath = "/path/pathname.txt";
File file = new File(filePath);

HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);

HttpEntity entity = MultipartEntityBuilder.create().addBinaryBody("file", file, ContentType.DEFAULT_BINARY, file.getName()).build();

httpPost.setEntity(entity);

try {
    HttpResponse response = httpClient.execute(httpPost);

} catch (IOException e) {
    e.printStackTrace();
}

  ]]></Source>
</Rule>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.