Skip to main content
Skip table of contents

Enabling Fax API via Mulesoft Anypoint Studio

Building a Cloud Fax Connector on Mulesoft Anypoint is beneficial because it allows for seamless integration of fax services into existing IT infrastructures, enhancing digital workflows. The Retarus Fax cloud-based solution offers scalability, cost savings, and high security standards, ensuring the protection of sensitive data. Additionally, it keeps companies future-proof by leveraging a modern platform. This tutorial will guide you through the steps to how a fax can be procesed from salesforce to retarus for send out via made the connection through Mulesoft Anypoint Studio.

Devloper: Customer/Partner

Category: Third-Party Integration for Cloud Fax

Prerequisites

  • Retarus Account: Ensure you have an active Retarus account with credentials to access to their Cloud Fax platform.

  • Mulesoft Account: Ensure you have administrative access to the Mulesoft Anypoint platform.

The guide explains the setup of a Retarus Outbound Cloud Fax REST API with the following steps:

  1. Sending fax data (Recipient, Header, Content) from Salesforce via REST-API

  2. Receiving the Fax in Mulesoft Anypoint Platform (Cloud Connector)

  3. Sending out the Fax from within Mulesoft Cloud to Retarus 

In this tutorial business faxes shall be addressed that have a pre-defined document structure such that their templates (Retarus wording: "Customer-specific Coversheet") are stored in the Retarus environment and don't have to be uploaded/ provided with every data push from within Salesforce.

image-20240821-082741.png

How to get started

1.Sending fax data

Configure a Salesforce Flow
The SF Flow can be configured based on your needs for sending fax data (Recipient, Header, Content, Optional: PDF Document) from Salesforce via REST-API

See in below Salesforce Flows:

  • Send Fax: Recipient, Subject, Fax Content

  • Send Fax_V2: Recipient, Subject, Fax Content, PDF

image-20240821-083702.png
  • Route the Salesforce Flow to a faxRequest class object (next step below) and prepare for send out via a connector on Mulesoft Anypoint

  • Send a PDF document via Cloud Fax
    Recipient, Header, Content, Optional: PDF Document; from Salesforce via REST-API

    global class RetarusFaxAPI_In { // @InvocableMethod(label = 'Send Fax' description='method description')

    CODE
    global static void callFAXApi_in(faxRequest[] requests){
        for (faxRequest request: requests) {
            Http http = new HTTP();
        	HttpRequest req = new HttpRequest();
        	HttpResponse res = new HttpResponse();
        	req.setEndpoint('https://faXXXXXXXXv1-7XXXz.5XXXX6-2.usa-e2.cloudhub.io/send');  // ALTERNATIVE WITHOUT MULESOFT: build the Retarus JSON Format within APEX Call including BasicAuth provided by Retarus Implementation for direct sending to Retarus
                            
        	String subject = request.subject;
            String msg = request.message;
            String message= EncodingUtil.base64Encode(Blob.valueOf(msg));
            
            Id cvId = request.contentVersionIds[0];
            ContentVersion cv = [SELECT Id,Title,VersionData FROM ContentVersion WHERE Id = :cvId LIMIT 1];
            Blob pdfBlob = cv.VersionData;
            String base64EncodedPDF = EncodingUtil.base64Encode(pdfBlob);
    		        	
        	String dst_number = request.dst_number;
        	JSONGenerator gen = JSON.createGenerator(true);
        	gen.writeStartObject();
        	gen.writeStringField('subject',subject);
        	gen.writeStringField('message',message);
        	gen.writeStringField('dst_number',dst_number);
            	gen.writeStringField('base64EncodedPDF',base64EncodedPDF);
            
        	gen.writeEndObject();
        	String jsonS = gen.getAsString();
        	System.debug(jsonS);
        	req.setBody(jsonS);
        	req.setHeader('Content-Type','application/json');
        	req.setMethod('POST');		        
        	res = http.send(req);
        	System.debug(res.getBody());
            	// DO SOMETHING WITH THE ANSWER 
    	string code = res.getBody();
        	}        
    }
     
      global class faxRequest {
      @InvocableVariable(required=true)
      global String subject; 
          
      @InvocableVariable(required=true)
      global String dst_number;
        
       @InvocableVariable(required=true)
       global String message;  
          
       @InvocableVariable(required=true)
       global List<Id> contentVersionIds;
       }
    

    }

Sample Salesforce Sending APEX-Code

  • Send a PDF document via Cloud Fax
    Recipient, Header, Content, Optional: PDF Document; from Salesforce via REST-API

    global class RetarusFaxAPI_In { // @InvocableMethod(label = 'Send Fax' description='method description')

    CODE
    global static void callFAXApi_in(faxRequest[] requests){
        for (faxRequest request: requests) {
            Http http = new HTTP();
        	HttpRequest req = new HttpRequest();
        	HttpResponse res = new HttpResponse();
        	req.setEndpoint('https://faXXXXXXXXv1-7XXXz.5XXXX6-2.usa-e2.cloudhub.io/send');  // ALTERNATIVE WITHOUT MULESOFT: build the Retarus JSON Format within APEX Call including BasicAuth provided by Retarus Implementation for direct sending to Retarus
                            
        	String subject = request.subject;
            String msg = request.message;
            String message= EncodingUtil.base64Encode(Blob.valueOf(msg));
            
            Id cvId = request.contentVersionIds[0];
            ContentVersion cv = [SELECT Id,Title,VersionData FROM ContentVersion WHERE Id = :cvId LIMIT 1];
            Blob pdfBlob = cv.VersionData;
            String base64EncodedPDF = EncodingUtil.base64Encode(pdfBlob);
    		        	
        	String dst_number = request.dst_number;
        	JSONGenerator gen = JSON.createGenerator(true);
        	gen.writeStartObject();
        	gen.writeStringField('subject',subject);
        	gen.writeStringField('message',message);
        	gen.writeStringField('dst_number',dst_number);
            	gen.writeStringField('base64EncodedPDF',base64EncodedPDF);
            
        	gen.writeEndObject();
        	String jsonS = gen.getAsString();
        	System.debug(jsonS);
        	req.setBody(jsonS);
        	req.setHeader('Content-Type','application/json');
        	req.setMethod('POST');		        
        	res = http.send(req);
        	System.debug(res.getBody());
            	// DO SOMETHING WITH THE ANSWER 
    	string code = res.getBody();
        	}        
    }
     
      global class faxRequest {
      @InvocableVariable(required=true)
      global String subject; 
          
      @InvocableVariable(required=true)
      global String dst_number;
        
       @InvocableVariable(required=true)
       global String message;  
          
       @InvocableVariable(required=true)
       global List<Id> contentVersionIds;
       }
    

    }

2. Receiving the Fax in Mulesoft Anypoint Platform (Cloud Connector)

Anypoint Studio Connector

  • Receiving the Fax in Mulesoft Anypoint Platform Instance (Cloud Connector)

  • Check that your connector works as expected in Anypoint Studio

  • Right Click on the *.xml of the connector in Anypoint Studio →  Click "Export". 

    image-20240821-090534.png

    In Listener-Block:

  • Listens on a port for requests from Salesforce, e.g. on Port 8081 on Path /send as shown below.

image-20240821-092529.png

In Transform Message Block:

  • Set the payload-Element where necessary in order to configure the deployed Mulesoft connector in the way you need it:

%dw 2.0 output application/json

{ "reference":{
"customerDefinedId": "Individual Job Reference Info_DEMO",
"billingCode": "00000",
"billingInfo": "Customer Billing Info - Demo"
}, "recipients": [{ "number": payload.dst_number,

"properties": [
{ "key": "FromName",
 "value": "Max Mustermann" },
{ "key": "FromCompanyName", "value": "Retarus GmbH" },
{ "key": "FromTelNum", "value": "+49123456789" },
{ "key": "ToName", "value": "John Doe" },
{ "key": "ToCompanyName", "value": "Rental Agency Woodcraft" },
{ "key": "ToFaxNum", "value": "+49123456789" },
{ "key": "SubjectTitle", "value": payload.subject } ]} ],
"documents": [{ "name": "Sample_pdf.pdf", "data": payload.base64EncodedPDF }],

"transportOptions": { "csid": "Postman Fax4A coverpage", "isExpress": false, "isBlacklistEnabled": false },
"renderingOptions": { "paperFormat": "A4", "resolution": "HIGH", "coverpageTemplate": "coverpage-default.ftl.html",
"header": "%tz=CEST Testfax: Fax4A-REST CSID: %C Empfaengernummer: %# Datum: %d.%m.%Y %H:%M %z" },
"statusReportOptions": { "reportPurgeTs": "2024-11-03T20:14:37.098+02:00",
"reportMail": { "successAddress": "john.doe@retarus.de", "failureAddress": "max.mustermann@retarus.de" } },
"meta": { "customerReference": "00000",
"jobValid": { "start": null, "end": null }

 } }

image-20240821-094157.png
  • Create Mule → "Anypoint Studio Project to Mule Deployable Archive (includes Studio metadata)"

image-20240821-094234.png
  • Export the mule project as a deployable Archive (*.jar) to a folder of your choice

image-20240821-094321.png

Export of the mule fax project

image-20240821-094344.png

Deployment of the application

image-20240821-094356.png

Deployment of the application

image-20240821-094512.png

Deployment of the application

3. Sending out the Fax from Mulesoft Cloud to Retarus 

Monitor the process through the Runtime manager

image-20240821-094540.png

Outbound request

image-20240821-094602.png

Confirmation of the recieved request at the Retarus endpoint

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.