2

How to send multipart/form-data from SAP Cloud Integration to the DocuSign Open...

 1 year ago
source link: https://blogs.sap.com/2022/10/24/how-to-send-multipart-form-data-from-sap-cloud-integration-to-the-docusign-open-connector-to-create-an-envelope-and-get-its-recipient-url/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
October 24, 2022 6 minute read

How to send multipart/form-data from SAP Cloud Integration to the DocuSign Open Connector to create an envelope and get its recipient URL

Hello!

In this blog post, you’ll learn how to send multipart/form-data in the SAP Cloud Integration service, in this case, while integrating with the DocuSign Open Connector. In addition, you’ll learn how to view and get the recipient URL of the DocuSign document, in case you want to embed it in your custom application.

Please bear in mind that this blog is for exercise purposes. Unfortunately, the Open Connector adapter in SAP Cloud Integration currently does not support sending multipart/form-data. So in this blog post, you’ll find an exercise as a workaround.

Prerequisites:

  • You have a SAP BTP account or trial account. If you don’t have an account, it is recommended to start using the several SAP BTP Free-Tier services available, this tutorial can help you. If you want to use the “regular” trial account, create one by registering here.
  • You have created an SAP Integration Suite instance, with Cloud Integration and Open Connectors added as capabilities.
  • You have created a DocuSign Open Connector instance. Here, you need to get your Open Connector credentials (User, Organization and Element (a.k.a. Instance Token)
  • You have created a DocuSign template. If you want to try the exercise but don’t have a DocuSign account, you can create a trial one here. If not sure how to create a template and get the template, you can follow the first steps of this previous blog post.

Let’s start with creating the envelope

Let’s create an Integration Package. I named it “DocuSign_OpenConnector”.

1-78.png

Create an Integration Flow in the Artifacts tab.

2-36.png
3-32.png

On the Edit mode, change the Sender’s name to Postman in the General tab, as we’re going to test it using Postman and connect it to the start event using an HTTPS adapter.

Add an Address/Path and uncheck the CSRF protection.

5-30.png

Add a Content Modifier. Here we will add the headers as we needed to call the DocuSign Open Connector:

  • Authorization: <User #####, Organization #####, Element #####> (Open Connector’s credentials)
  • Content-Type: multipart/form-data; boundary=————-12345
  • accept: application/json
6-31.png

Change the Message Body to “Expression” and leave Exchange Property empty, we are going to pass the payload directly when calling the endpoint.

Add a Groovy Script and create a script.

7-21.png

Copy and paste this code:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    //Body 
       def body = message.getBody(String);
       body = body.replaceAll("\n", "\r\n");
       body = """---------------12345\r\nContent-Disposition: form-data; name="envelope"\r\n\r\n""" + body + """\r\n\r\n---------------12345--"""

       message.setBody(body);
       return message;
}

I was getting a 400 error “Unable to parse multipart body” in SAP Cloud Integration, despite being able to call directly the DocuSign Open Connector in the Open Connector Service. For this reason, I needed to find a workaround to pass multipart/form-data through the Integration Flow. Many thanks to my colleague Rafael Moncayo who helped me to conduct this integration step and also to this great blog post from Matti Leydecker

You should see it like this:

8-15.png

Add a Request Reply Call and connect it to the Receiver using an HTTP adapter.

Despite using an Open Connector endpoint, unfortunately -as mentioned at the beginning of the blog-, the Open Connector adapter does not support at the moment multipart/form-data. For this reason, we need to configure it using an HTTP receiver adapter.

Add your Open Connector URL, and the headers you have declared in the previous Content Modifier. You should have this adapter configured as the screenshot below:

9-15.png

Save and deploy your Integration Flow.

Then, go to Monitor Integration Content, select your recently deployed Integration Flow and change the Log Configuration to “Trace“, we are going to test the Integration Flow.

10-13.png

Copy your Integration Endpoint, add your SAP Integration Suite credentials as Authorization in Postman and, add your needed Payload for creating the DocuSign envelope.

This is the Sample Payload I used. This is going to depend on how many input values you added to your DocuSign template.

{
    "templateId": "<DocuSign template Id>",
    "emailSubject": "DocuSign Subject From Postman",
    "status": "sent",
    "templateRoles": [
        {
            "email": "<Signer's email>",
            "name": "Mariajose Martinez",
            "roleName": "Signer",
            "tabs": {
                "textTabs": [
                    {
                        "tabLabel": "fullName",
                        "value": "Postman is sending this Name Value"
                    }
                ]
            }
        }
    ]
}

Test the call:

11-10.png

You’ll get a success call, and here you can check the envelopeId. We are going to get to this part later.

You should have received the email too.

12-12.png
15-8.png

Now, let’s get back to check the Trace.

Click on Monitor Message Processing and then Trace:

13-9.png

Check how the Payload gets embedded in the Message body.

14-12.png

Very good. Now let’s get the Recipient URL.

Let’s get now the Recipient URL

Let’s get back to the Integration Flow, and add a JSON to XML converter. We need this to apply an XPath to create a URL property. Make sure the “Add XML Root Element” is checked.

In this case, as the Payload has many roots, SAP Cloud Integration needs the message to have a single root in the XML message. In this way, we are going to be able to get the URL property.

16-10.png

Add a Content Modifier. Leave the Message Header empty as we are going to reuse the ones declared in the first Content Modifier.

Go to Exchange Property and let’s create the envelopeId property as shown in the screenshot, with the source value /root/envelopeId :

17-10.png

In the Message Body, add this JSON payload as a constant. Here we need to add a Callback URL for when the DocuSign document is already signed.

Sample Payload:

{
    "authenticationMethod": "None",
    "email": "<your email>",
    "recipientId": "1",
    "returnUrl": "https://www.sap.com/canada/index.html",
    "userName": "<your DocuSign email account>"
}

Like this:

18-7.png

Add another Request Reply call and change the name to “Recipient URL”

Add another Receiver as DocuSign and configure the HTTP adapter.

Check that the Open Connector endpoint is a little bit different. This time we need to point to the /envelopes/${property.envelopeId}/recipient-views.

The property envelopeId is the one created in the previous Content Modifier. Type the headers again, as shown in the picture:

19-8.png

Save and deploy your Integration Flow.

Test it again in Postman:

20-8.png

With this, you are going to be able to embed this URL in your custom application if you want to.

Conclusions

  • You have learned how to send multipart/form-data in SAP Cloud Integration to create an envelope connecting with the DocuSign Open Connector.
  • In addition, you have learned how to get the recipient URL for cases where you want to embed the DocuSign document in your custom application.

Hope you’ve enjoyed this quick exercise 🙂


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK