Support for Multipart Request Body

IBM webMethods Integration supports the multipart/form-data media type that uses which you can embed binary data such as files into the request body. Though application/x-www-form-urlencoded is a more natural way of encoding, it becomes inefficient for encoding binary data or text containing non-ASCII characters. The media type multipart/form-data is the preferred media type for request payloads that contain files, non-ASCII, and binary data.

For example, if you want to create a user as well as upload a photo, the request must be a multipart request where one part is an image file while the other part is a JSON request body. Further, uploading the CRM individual contact data to Salesforce is time consuming, so that uses the MIME/Multipart attachments capability, you can upload the csv/JSON file containing multiple contacts data into Salesforce in a single run.

For some connectors and operations, for example, for SalesforceR Bulk v2 Data Loader, DocuWare, Google Drive, Amazon S3, and FreshService, IBM webMethods Integration supports a multipart request body.

Example of a multipart request

A multipart/form-data request body contains a series of parts that are separated by a boundary delimiter, which is constructed that uses Carriage Return Line Feed (CRLF), "--", and also the value of the boundary parameters. The boundary delimiter must not appear inside any of the encapsulated parts.

Each part has the Name, Type, Content-Type, and Part ID fields.


--BOUNDARY
Content-Type: application/json
Content-Disposition: form-data; name="job"

{
"object":"Contact",
"contentType":"CSV",
"operation":"insert"
}
--BOUNDARY
Content-Type: text/csv
Content-Disposition: form-data; name="content"; filename="content"
(Content of your CSV file)
--BOUNDARY—

Part Configuration

While adding a custom action, for example, for the Freshservice Create Child Ticket With Attachments operation, you can click Attachments to view the list of all the configured parts to be sent to the service provider. You can send a multipart/form-data payload, which contains either a file, or text, or a document type.

The parts to be sent to the service provider appear in the input signature. All options including the Add option to add a custom part are disabled if the resource is not of type of multipart/form-data. Currently, multipart/form-data payload is supported only at the request level, that is, only in the input signature.

  • Name - Name of the file part as documented in the SaaS provider API documentation.
  • Content Type - Content type of the part's content (if the Type is TEXT), or the file you are uploading (if the Type is FILE) or the serialization type to which the document will be serialized and become the part content (if the Type is DOCUMENT).
  • Type - IBM webMethods Integration defines the following three-part types:
    • TEXT - Represents a simple text part of a multipart/form-data payload where the content of the part is of type text/plain. You can use this part to send raw text data as the content of a part, in a multipart request. From a file upload perspective, this part is used to convey extra information about the upload behavior, like target folder paths/folder names where the file must be uploaded.
    • DOCUMENT - Some back ends expect application/JSON or application/xml content in the part body. This represents a part where the content of the part is of the type application/JSON or application/xml.
    • FILE - Represents a binary part of a multipart/form-data payload where the content of the part is binary or the content of the file itself. To upload a file, you will normally use this part. For file upload use cases, this part is the main or mandatory part that is required by the service provider.
  • Active/Inactive - Represents whether this part will be included as part of the service signature.

Example to create a ticket with attachments (multipart data) in Freshservice

Before you begin

  • Log in to your tenant.
  • Check whether you have the Developer and Admin roles that are assigned from the User Management > Roles page.
  • Obtain the credentials to log in to the Freshservice back-end account.
  • In IBM webMethods Integration, create a File Transfer Protocol (FTP/FTPS) account FTPS_4 and a Freshservice account Freshservice_1.

Basic Flow

  1. Select the project where you want to create the new flow service. You can also create a new project.

  2. Click the Flow services tab and on the Flow services page, click the icon.

  3. Provide a name for the flow service, for example, CreateTicketWithAttachment, and an optional description for the new flow service.

  4. Upload a file from the FTP server to Freshservice. Select the File Transfer Protocol (FTP/FTPS) connector, the getFile operation, and the FTPS_4 account.

  5. Let us upload the hello.txt file available on the FTP server in Freshservice. Click Set Value for remoteFile and select the same file in the Set Value - remoteFile dialog box. Click Save.

  6. Select the Freshservice connector. As you are creating a ticket with an attachment, select the createTIcketWithAttachment operation and the account as Freshservice_1.

  7. Click the Edit Mapping icon. Under Pipeline Input, map contentStream to value.

  8. Set the following values on the mapping screen:

    • Set the value for file name as hello.txt.
    • Set the value for email as abc@xxxx.com.
    • Set the value for subject as create ticket.
    • Set the value for description as create ticket with attachment.
    • Set the value for priority as 1.
    • Set the value for status as 2.
    • Set the value for requester_id as 27000450816. This is the agent ID in Freshservice.
    • Set the value for phone as 123456789.
    • Set the value for source as a test.
  9. Save and run the flow service.
  10. Go to Freshservice, click Tickets, and check that the ticket is generated.

Create bulk accounts in Salesforce using a multipart predefined operation

For some connectors and operations, for example, for the Salesforce R Bulk v2 Data Loader connector and createAndUploadDataUsingMultipart predefined operation, IBM webMethods Integration supports multipart request body.

Before you begin

  • Log in to your tenant.
  • Check whether you have the Developer and Admin roles that are assigned from the User Management > Roles page.
  • Obtain the credentials to log in to the Salesforce back end account.
  • In IBM webMethods Integration, create the Salesforce R Bulk v2 Data Loader account, SFBulkV2_02Apr.

Basic Flow

  1. Select the project where you want to create the new flow service. You can also create a new project.
  2. Click the Flow services tab and on the Flow services page, click the icon.
  3. Provide a name and an optional description for the new flow service.
  4. Type IO in the search box, select IO, and then select the stringToStream service.
  5. Click the mapping icon to map the input and output fields.
  6. Set the following value for string:
  7. Set the value for encoding as UTF-8.
  8. .Click the icon to add a new step.
  9. Select the Salesforce(R) Bulk v2 Data Loader connector and the createAndUploadDataUsingMultipart predefined operation. Select the SFBulkV2_02Apr account.
  10. Click the mapping icon to map the input and output fields.
  11. Map inputStream to value. The service output is automatically mapped to the Pipeline Output by a dotted line.
  12. Set values for fileroot
  13. For fileRoot1, set values for name as content, contentType as text/csv, type as FILE, and file name as content.
  14. Save the flow service and run it by clicking the Run icon.
  15. View the flow of service execution results for a successful run.