Contact Us 1-800-596-4880

SAP SuccessFactors Connector 4.0 - Examples - Mule 4

These examples show how to create flows to invoke some of SAP SuccessFactor’s standard operations, including how to:

Before You Begin

To build and run these flows, you need:

  • OpenJDK 8 or 11

  • Anypoint Studio 7.1 or later

  • Mule 4.2.2 or later

  • SuccessFactors Connector 3.x or later

  • SuccessFactors credentials to send OData API requests

  • DataWeave 2.0

Create a Mule Project

In Studio, create a new Mule project in which to add and configure the connector:

  1. In Studio, select File > New > Mule Project.

  2. In Project Name, enter a name for your Mule project.
    This example uses the name successfactors-operations.

  3. Click Finish.

Specify Your Credentials

  1. In Package Explorer, under /src/main/resources/, create a file named mule-app.properties.

  2. Specify your credentials for connecting to SuccessFactors, for example:

    config.companyId=<your-company-id>
    config.userName=<successfactors-username>
    config.password=<successfactors-password>
  3. Save the file.

Configure a Global Element for the Connector

Configure a global element to provide the authentication credentials that the connector requires to access the target SuccessFactors system.

  1. At the base of the Studio canvas, click Global Elements.

  2. Select SAP SuccessFactors Config and click Edit.

  3. In the SAP SuccessFactors Configuration window, enter the connection credentials as follows:

    • Company ID: ${config.companyId}

    • User Name: ${config.userName}

    • Password:`${config.password}`

  4. From the Data Center’s Endpoint URL drop-down, select the SuccessFactor’s Web API URL.

    The following image shows an example of configuring Basic authentication:

    image::sap-successfactors-basic-config.png

  5. Click OK.

  6. Click Test Connection to verify the connection to SAP SuccessFactors.

    A success message appears.

Create the Query Operation Flow

Create a flow that uses the Query operation to perform queries over entities of a specified type:

  1. In the Mule Palette view, select HTTP > Listener.

  2. Drag Listener to the Studio canvas.

  3. On the Listener configuration screen, optionally change the value of the Display Name field.

  4. Specify /list for the Path field.

  5. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of HTTP Listener in the app.

    1. On the General tab, specify connection information for the connector.

    2. Click Test Connection to confirm that Mule can connect with the specified server.

    3. Click OK.

  6. In the Mule Palette view, select SAP SuccessFactors, then select the Query operation and drag it on to the Studio canvas to the right of the Listener operation.

  7. In the left pane of the Mule Palette, click Favorites.

  8. Select Transform Message and drag it on to the Studio canvas to the right of the Query operation.
    The Transform Message component transforms the data structure and format to produce the output the connector expects, in this case, application/json:

    %dw 2.0
    output application/json
    ---
    payload
  9. Add a Logger component to the end of the flow that takes a payload (or #[payload]) as the message.

The following image shows the SuccessFactors Query operation flow:

Mule flow using an HTTP Listener source, SuccessFactory Query operation, Transform Message, and Logger components.

XML for Creating a Query

This is the XML for the Query operation flow:

<flow name="Query" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config2" path="/list"/>
        <successfactors:query entitySetName="User" doc:name="Query" config-ref="SuccessFactors_Configuration" >
		</successfactors:query>
		<ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>

Test the Flow

To test the flow:

  1. Run the app.

  2. Open a browser.

  3. Navigate to http://localhost:8081/list.

Create an Entry on SuccessFactors Example

The following flow uses the SuccessFactors Create entity operation to create an entry on SuccessFactors:

Mule flow using an HTTP Listener source

XML for Creating an Entry

This is the XML for the Create entity operation flow:

<flow name="Create-Entry">
           <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createVendor"/>
           <ee:transform doc:name="Transform Message">
               <ee:message >
                   <ee:set-payload ><![CDATA[%dw 2.0
   output application/java
   ---
   {
       vendorCode: "XYZ123ABC",
       effectiveStartDate: "2018-07-08T00:00:00"  as DateTime,
       effectiveStatus: "I"
   }]]></ee:set-payload>
               </ee:message>
           </ee:transform>
           <successfactors:create-entity doc:name="Create entity"
	   config-ref="SuccessFactors_Configuration" entitySetName="VendorInfo"/>
           <ee:transform doc:name="Transform Message" >
               <ee:message >
                   <ee:set-payload ><![CDATA[%dw 2.0
   output application/json
   ---
   payload]]></ee:set-payload>
               </ee:message>
           </ee:transform>
           <logger level="INFO" doc:name="Logger" message="#[payload]"/>
       </flow>

Test the Flow

To test the flow:

  1. Run the app.

  2. Open a browser.

  3. Navigate to http://localhost:8081/create.

Get Entity by ID Flow

The following flow uses the Get entity by id operation to retrieve an entity by ID:

Mule flow using an HTTP Listener source

XML for Getting an Entity by ID

This is the XML for the Get entity by id flow:

<flow name="Get-Entity-by-Id">
           <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/getById"/>
           <ee:transform doc:name="Transform Message">
               <ee:message>
                   <ee:set-payload><![CDATA[%dw 2.0
   output application/java
   ---
   {
   	effectiveStartDate: attributes.queryParams.effectiveStartDate as DateTime,
   	vendorCode: attributes.queryParams.vendorCode
   }]]></ee:set-payload>
               </ee:message>
           </ee:transform>
   		<successfactors:get-entity-by-id entitySetName="VendorInfo" doc:name="Get entity by id"
		config-ref="SuccessFactors_Configuration" />
           <ee:transform doc:name="Transform Message">
               <ee:message >
                   <ee:set-payload ><![CDATA[%dw 2.0
   output application/json
   ---
   payload]]></ee:set-payload>
               </ee:message>
           </ee:transform>
           <logger level="INFO" doc:name="Logger" message="#[payload]"/>
       </flow>

Test the Flow

To test the flow:

  1. Run the app.

  2. Open a browser.

  3. Navigate to http://localhost:8081/getById.

Update an Entry on SuccessFactors

The following flow uses the SuccessFactors Update operation to update an entry on SuccessFactors:

Mule flow using an HTTP Listener source

XML for Updating an Entry

This is the XML for the Update operation flow:

<flow name="Update" >
        <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/update"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: nowTime ,
	mdfSystemExternalCode:"TV60" ++ uuid(),
	cust_effectiveStatus:"A"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:create-entity entitySetName="cust_VendorInfo" doc:name="Create entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[output application/java
var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: payload.effectiveStartDate,
	mdfSystemExternalCode: payload.mdfSystemExternalCode,
	cust_effectiveStatus: payload.cust_effectiveStatus
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:update entitySetName="cust_VendorInfo" doc:name="Update"
        config-ref="SuccessFactors_Configuration"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>

Test the Flow

To test the flow:

  1. Run the app.

  2. Open a browser.

  3. Navigate to http://localhost:8081/update.

Delete an Entry on SuccessFactors

The following flow uses the SuccessFactors Delete entity operation to delete an entry on SuccessFactors:

Mule flow using an HTTP Listener source

XML for Updating an Entry

This is the XML for the Delete entity operation flow:

<flow name="Delete-Entry" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config" path="/delete"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: nowTime ,
	mdfSystemExternalCode:"TV60" ++ uuid(),
	cust_effectiveStatus:"A"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:create-entity entitySetName="cust_VendorInfo" doc:name="Create entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[output application/java
var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: payload.effectiveStartDate,
	mdfSystemExternalCode: payload.mdfSystemExternalCode,
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:delete-entity entitySetName="cust_VendorInfo" doc:name="Delete entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>

Test the Flow

To test the flow:

  1. Run the app.

  2. Open a browser.

  3. Navigate to http://localhost:8081/delete.

XML for SuccessFactor Operations

Paste this code into your Studio XML editor to quickly load all of the flows for these examples into your Mule app:

?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
      xmlns:successfactors="http://www.mulesoft.org/schema/mule/successfactors" xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/successfactors http://www.mulesoft.org/schema/mule/successfactors/current/mule-successfactors.xsd">
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <successfactors:config name="SuccessFactors_Configuration" doc:name="SuccessFactors Configuration" >
        <successfactors:basic-connection companyId="${config.companyId}" userName="${config.userName}" password="${config.password}" endpointUrl="https://api4.successfactors.com/odata/v2/"/>
    </successfactors:config>
    <configuration-properties doc:name="Configuration properties" file="mule-app.properties" />
    <http:listener-config name="HTTP_Listener_config1" doc:name="HTTP Listener config" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<http:listener-config name="HTTP_Listener_config2" doc:name="HTTP Listener config" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<flow name="Query" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config2" path="/list"/>
        <successfactors:query entitySetName="User" doc:name="Query" config-ref="SuccessFactors_Configuration" >
		</successfactors:query>
		<ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>

    <flow name="Create-Entry" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config" path="/create"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: nowTime ,
	mdfSystemExternalCode:"TV60" ++ uuid(),
	cust_effectiveStatus:"A"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:create-entity doc:name="Create entity"  config-ref="SuccessFactors_Configuration" entitySetName="cust_VendorInfo"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>

    <flow name="Get-Entity-by-Id" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config" path="/getById"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
	userId: "PSADMIN"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:get-entity-by-id entitySetName="User" doc:name="Get entity by id"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>
    <flow name="Update" >
        <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/update"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: nowTime ,
	mdfSystemExternalCode:"TV60" ++ uuid(),
	cust_effectiveStatus:"A"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:create-entity entitySetName="cust_VendorInfo" doc:name="Create entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[output application/java
var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: payload.effectiveStartDate,
	mdfSystemExternalCode: payload.mdfSystemExternalCode,
	cust_effectiveStatus: payload.cust_effectiveStatus
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:update entitySetName="cust_VendorInfo" doc:name="Update"
        config-ref="SuccessFactors_Configuration"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>


    <flow name="Delete-Entry" >
        <http:listener doc:name="Listener"
        config-ref="HTTP_Listener_config" path="/delete"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: nowTime ,
	mdfSystemExternalCode:"TV60" ++ uuid(),
	cust_effectiveStatus:"A"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:create-entity entitySetName="cust_VendorInfo" doc:name="Create entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message>
                <ee:set-payload><![CDATA[output application/java
var nowTime = (now()  as String {format:"yyyy-MM-dd"} ++ "T00:00Z[UTC]") as DateTime
---
{
	effectiveStartDate: payload.effectiveStartDate,
	mdfSystemExternalCode: payload.mdfSystemExternalCode,
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <successfactors:delete-entity entitySetName="cust_VendorInfo" doc:name="Delete entity"
        config-ref="SuccessFactors_Configuration" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>
</mule>
View on GitHub