K2 Endpoint Assembly, Integrate Muhimbi Convert to PDF REST API

In one of my recent  blog posts, we integrated the Muhimbi PDF Converter Service online Swagger file with K2  Server using the REST Service broker

The blog post on how to setup the integration, was a three part blog and setting up the REST Service type was a more advanced topic than many users may have been comfortable with, as it required some knowledge of REST, endpoints, entities, and HTTP. 

To simplify the integration process in this post, we will utilize the K2 Endpoints Assembly Service Broker and expose The Muhimbi REST API as .NET Assemblies and a SmartObject.

Before we begin, make sure the following prerequisites are in place.

  • Muhimbi PDF Converter Services Online, free or trial subscription(Sign up).
  • K2 Server configured for SharePoint Server.
  • Appropriate privileges to K2 Management portal
  • Basics of C# programming (You can download the sample-code here).

So, without wasting further time lets configure Muhimbi “Convert to PDF” SmartObject using K2 Endpoints Assembly Service Broker.

Now that the prerequisites are in place, let’s configure The Muhimbi “Convert to PDF” SmartObject using K2 Endpoints Assembly Service Broker.

First, we register a Service Instance against a .NET assembly.

  • Download the Source Code and extract the .zip file to a folder on K2 server.
  • Launch the SmartObject Server Tester located in the (Start > All Programs > K2 blackpearl > SmartObject Service Tester.exe) menu.
  • Expand the ServiceObject Explorer below and locate the Endpoints Assembly Service Object. Right-click the object and select Register ServiceInstance.
  • In the “Assembly Full Path – Required” property below, enter the full path of the assembly you extracted.
  • Change the “Display Name” and “Description” below and then click Add.
  • The following prompt should confirm “Service Instance added successfully” as shown below.
  • You should then be able to see the “Convert_To_PDF” Service Instance as shown below.

Deploy and test the Advanced SmartObject

  • Expand the “ServiceObject Explorer” and locate the “Endpoints Assembly” and expand it, if required. Right-click on the ‘Convert_To_PDF’ Service Instance and click on ‘Create SmartObjects’.
  • On the “Create SmartObjects” screen, select “Class1Objects” and the method “convert_to_pdf” and click on OK as shown below.
  • The following prompt should confirm that the ‘SmartObject’ was successfully created.

Testing the SmartObject

  • Launch SmartObject Services Tester, and navigate to the SmartObject Explorer > Expand the Convert_To_PDF method.  Right-click on the “Convert_To_PDF” Service Instance and click on “Execute SmartObject”.
  • On the screen below, select the “Method to Execute” as “Read”.
    • API_Key : <Your secret API_Key>
    • Source_file_name: clavin.txt
    • Source_file_content: TXVoaW1iaSByb2Nrcw==
    • Output_fomat: PDF

Note: API Key you received by email when signing up for the Muhimbi PDF Converter Services Online. e.g.: decafbad-baad-baad-baad-decafbaaaaad

  • Now, on successful execution of the SmartObject, you should get a String(Text). Now, you might be confused as to why are you getting an empty response.
  • The response is a base64 encoded, which is too long and hence the textbox cannot accommodate it. But the data is there!!
  • Right click in the String(Text) box, Select ALL and then copy. When you paste, the content in the Notepad you will get a base64 bit encoded string. See screenshot below.

Congrats, you have now successfully created the Muhimbi “Convert to PDF” SmartObject without the added complexity of using the REST Service Instance! 

You can now use this SmartObject in your Workflows and Automate the PDF Conversion Process; from a high level your Workflow would look like the screenshot below.

For more details on how to create the workflow see article.

Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.

Posted in K2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s