0

I wanna consume a REST service exposed by Salesforce, right now I'm using a Sandbox instance and using Anypoint Studio to create my flow, I would like to know what's the best practice to implement it. Now I'm not sure about the salesforce connector allows me to consume the service, so, I'm using this components:

This is whole flow.

<mule xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:oauth2="http://www.mulesoft.org/schema/mule/oauth2" 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:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd">
    <http:request-config name="HTTP_Request_Configuration" host="https://test.salesforce.com" port="80"  doc:name="HTTP Request Configuration" protocol="HTTPS">
        <oauth2:client-credentials-grant-type clientId="3xQYwWqsvZUYbwMRLHiXQy9A23XXXtxg1OMxdXh5p4eoev53q26CmN0Yx0EyLf_HTLW9X" clientSecret="710XXX1723685311">
            <oauth2:token-request tokenUrl="https://test.salesforce.com/services/oauth2/token"/>
        </oauth2:client-credentials-grant-type>
    </http:request-config>
    <file:connector name="File" writeToDirectory="/Users/emoran/Desktop" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
    <flow name="outbrain_3wintegrationFlow1">
        <poll doc:name="Poll">
            <fixed-frequency-scheduler frequency="10" timeUnit="SECONDS"/>
            <http:request config-ref="HTTP_Request_Configuration" path="services/apexrest/outbrain_integration_messages/" method="GET" requestStreamingMode="ALWAYS" sendBodyMode="ALWAYS"  doc:name="Consume SFDC LOG Service" doc:description="prueba" parseResponse="false" source="#[message.payload]" target="#[message.payload]">
                <http:request-builder>
                </http:request-builder>
                <http:success-status-code-validator values="0..599"/>
            </http:request>
        </poll>
        <logger message="&gt;&gt;&gt;&gt; RESPONSE FROM SERVER:  #[message.payload]" level="DEBUG" doc:name="Logger"/>
        <echo-component doc:name="Echo"/>
        <file:outbound-endpoint path="/" outputPattern="refacciones.json" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>

What would be the best approach to consume this service?

Edgar,

1
  • If it is a REST endpoint, why would it be different if it is exposed via Salesforce?
    – jackrabb1t
    Mar 20, 2015 at 20:30

2 Answers 2

1

Salesforce connector in Mule allows you to consume all the services exposed by Salesforce. You should use Salesforce connector within you poll scope to get data from Salesforce.

A simple example for your requirement is shown below.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:context="http://www.springframework.org/schema/context" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <context:property-placeholder location="file:${mule_home}/conf/salesforce-config.properties"/>
    <sfdc:config name="Salesforce" doc:name="Salesforce" password="${sf_password}" securityToken="${sf_security_token}" url="${sf_url}" username="${sf_username}">
        <sfdc:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
    </sfdc:config>
    <flow name="sfdcpollerFlow1" doc:name="sfdcpollerFlow1">
        <poll doc:name="Poll">
            <sfdc:get-updated config-ref="Salesforce"  doc:name="Salesforce" duration="10" type="Contract"/>
        </poll>
        <logger message="RESPONSE FROM SERVER:  #[payload]" level="INFO" doc:name="Logger"/>
        <echo-component doc:name="Echo"/>
        <file:outbound-endpoint path="${file_path}" outputPattern="refacciones.json" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>

In the above example, I am fetching modified contacts and placing that to a folder. You can refer the mule soft documents for more details on Salesforce connector.

http://www.mulesoft.org/documentation/display/current/Salesforce+Connector http://www.mulesoft.org/documentation/display/current/Connect+with+Salesforce+Example

1
  • Thanks, in the end to use salesforce connector is better than expose a service, get all information and transforme it. It is the best approach and best practice.
    – Edgar
    Jun 5, 2015 at 14:21
1

Using the HTTP connector in Mule to interface with Salsforce's Rest API is perfectly valid. However as others have mentioned the Salesforce connector abstracts away a lot for complexity when dealing with the Salesforce APIs including authentication and connection management etc.

I noticed your example uses OAuth, the other examples are using basic/ws security but the Salesforce connector also support OAuth: http://www.mulesoft.org/documentation/display/current/Salesforce+Connector+Authentication

However under the hood the Salesforce connector primarily uses the Salesforce SOAP API. So if you have a particular need to use the Rest API then the connector might not help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.