Mule Rest Post call to SFDC to create a lead - rest

I need to post a Rest call to SFDC with the respective credentials and create the SalesLead in SFDC. The response should come inthe form of Acknowledgment JSON response.
I am not sure how to use http:rest-service-component to post the data for creating lead.
Any help or sample is appreciated...

It is resolved now by using the "https:outbound-endpoint". All this code need is a JSON object as input.
Below is the snippnet:
<https:outbound-endpoint
method="POST" exchange-pattern="request-response"
address="url"
contentType="application/json" doc:name="HTTP" >
<message-properties-transformer scope="outbound">
<add-message-property key="Authorization" value="OAuth ****"/>
</message-properties-transformer>
</https:outbound-endpoint>
<echo-component doc:name="Echo"/>

Related

transaction flow with roll back strategy mule

Input:-
<balanceInquiry>
<request>
<amount>
<amount>5.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
<balanceInquiry>
<request>
<amount>
<amount>10.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
<balanceInquiry>
<request>
<amount>
<amount>57.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
I am trying to hit a SOAP webservice using the above input, but the webservice can only accept one balanceInquiry request at once. So I am spliting the request into different balanceInquiry using splitter. but if the status of 1st request is success then I have to go for 2nd and so on. If anyone of them fails then I need to rollback all the previous transaction. there is a attribute which can be "success" or "fail" depending on the request.
So I want to know if there is any component to achieve this in mule? Please suggest.
I believe you should take a look at the foreach documentation. https://docs.mulesoft.com/mule-user-guide/v/3.7/foreach and the exception handling strategy ; https://docs.mulesoft.com/mule-user-guide/v/3.7/error-handling.
If your 3 inquiries are in the same message and that you are using the default exception strategy, it will rollback the previous transactions... assuming you are writing the SOAP responses in a database using a DB connector.
Since I don't know exactly what you wish to do in your transaction, here's another interesting link : https://docs.mulesoft.com/mule-user-guide/v/3.7/rollback-exception-strategy

REST request in SOAP UI

I am trying to make a REST POST request in SoapUI.. The XML contract for the same is
<Login>
<Email>admin</Email>
<Password>123456</Password>
</Login>
I have passed the values as follows in the REST request in SoapUI to the URL http://localhost:8080/SalesPropeller/rest/api/restLogin
Name Value Style level
Email admin Query Resource
Password 123456 Query Resource
How do I pass the parameters in SoapUI?
Should the root tag name be included?If yes, How?
It is based on how your backend expects the payload.
From XML Contract, Your request payload should be like this
<Login>
<Email>admin</Email>
<Password>123456</Password>
</Login>
If you want to add properties, to send variables as field values
<Login>
<Email>${propertyName}</Email>
<Password>${propertyName}</Password>
</Login>
For creating properties, refer http://www.soapui.org/functional-testing/properties/working-with-properties.html

Flow Vars getting lost after Facebook Authorize in MuleStudio

I have a simple Flow to authorize to Facebook and then to post a Message.
<flow name="drupal-esbFlow2" doc:name="drupal-esbFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<set-variable variableName="facebookMSG" value="#[message.inboundProperties['msg']]" doc:name="Variable"/>
<facebook:authorize config-ref="Facebook" doc:name="Authorize"/>
<set-session-variable variableName="accessTokenId" value="#[flowVars['OAuthAccessTokenId']]" doc:name="Get OAuthAccessTokenId"/>
<facebook:publish-message config-ref="Facebook" msg="#[flowVars['facebookMSG']]" profile_id="100001574667695" accessTokenId="#[sessionVars['accessTokenId']]" doc:name="Publish Message"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
The Idea is that i want to hit the endpoint localhost:8082?msg=myMessage. Then i want to safe the inboundProperties['msg'] in a Flow Variable and use this in the Facebook Connector. But it seems that the Variables gets lost in the Transport...
I have read that this is an known issue (mule facebook - flow variable), but is there no walk around or something?
Well as the answer sort of alludes to, it seems the authorize mp is intended to be called in complete isolation of any other logic and simply return the access token id via an http:response-builder. The client is then responsible for sending the access token id to another flow for any other processing:
<flow name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
<facebook:authorize/>
<http:response-builder status="200">
<http:set-cookie name="accessTokenId" value="#[flowVars['OAuthAccessTokenId']]"/>
<set-payload value="You have successfully authorized the connector. You access token id is #[flowVars['OAuthAccessTokenId']]"/>
</http:response-builder>
</flow>
I can sort of see why, but makes you architect your app in a very specific way.
The other options is to use the "state" parameter. But this depends on on what types of data you're in your flow vars. Example:
<facebook:authorize state="#[flowVars.myvalue]"/>
This will then get returned in the callback as an inbound property that can be retrieved via:
#[message.inboundProperties['state']]
etc.
Alternatively you could look at persisting certain values, possibly in the mule object-store.

Debugging 500 Response for Create Sales Receipt Through API Explorer

I've been developing an IPP application using the PHP devkit. I've been using the XML returned from the $object->asIDSXML() method to debug my objects through the API Explorer. Within the API Explorer I have been recieving a very ambiguous error when trying to create a Sales Receipt and I'm hoping I can learn more about the scheme requirements. Is there a validation xsd file somewhere? I'm currently unable to understand why I receive the following 500 code.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <FaultInfo
xmlns="http://www.intuit.com/sb/cdm/baseexceptionmodel/xsd">
<Message>Internal Server Error</Message>
<ErrorCode>500</ErrorCode>
<Cause>SERVER</Cause> </FaultInfo>
The documentation regarding a 500 states something along the lines of :
Possible Causes:
Illegal permissions.
Illegal values that are not verified in the validation process.
Invalid data that the business logic verified.
I know that I have proper permissions, I have authenticated with an OAuth Token that has all privileges. The later two possibilities I believe are the issue, but I don't know how to get any additional information regarding the potentially invalid or missing data. I have literally tried creating a duplicate by using the API explorer to retrieve the SalesReceipt XML and then removing the DocumentID and sending to a create POST through the API explorer at which point I receive the same error shown above.
The following is the XML post data provided to the API. As far as I can tell the xml contains all the required fields fore creating a Sales Receipt. Thanks in advance for any help.
<SalesReceipt>
<Header>
<TxnDate>2013-04-16-07:00</TxnDate>
<CustomerId idDomain="QBO">78</CustomerId>
<TotalAmt>4.00</TotalAmt>
<ShipAddr>
<Line1>123 Fake Ave</Line1>
<City>Fake City</City>
<CountrySubDivisionCode>ID</CountrySubDivisionCode>
<PostalCode>83854</PostalCode>
</ShipAddr>
</Header>
<Line>
<Id>1</Id>
<Desc>Face to face IT Consulting Services, providing solutions to client's IT issues.</Desc>
<Amount>4.00</Amount>
<Taxable>false</Taxable>
<ItemId>17</ItemId>
<UnitPrice>4.00</UnitPrice>
<Qty>1</Qty>
</Line>
</SalesReceipt>
Can you please try the following
<SalesReceipt xmlns='http://www.intuit.com/sb/cdm/v2'>
<Header xmlns:ns3='http://www.intuit.com/sb/cdm/v2'>
<ns3:TxnDate>2013-04-16-07:00</ns3:TxnDate>
<ns3:CustomerId>78</ns3:CustomerId>
<ns3:TotalAmt>4.00</ns3:TotalAmt>
<ShipAddr>
<Line1>123 Fake Ave</Line1>
<City>Fake City</City>
<CountrySubDivisionCode>ID</CountrySubDivisionCode>
<PostalCode>83854</PostalCode>
</ShipAddr>
</Header>
<Line xmlns:ns11='http://www.intuit.com/sb/cdm/v2'>
<ns11:Id>101</ns11:Id>
<ns11:Desc>Face to face IT Consulting Services, providing solutions to client's IT issues.</ns11:Desc>
<ns11:Amount>4.00</ns11:Amount>
<ns11:Taxable>false</ns11:Taxable>
<ns11:ItemId>17</ns11:ItemId>
<ns11:UnitPrice>4.00</ns11:UnitPrice>
<ns11:Qty>1</ns11:Qty>
</Line>
</SalesReceipt>

How to throw Soap Fault manually in mule

I'm face with a situation where we cannot use schema to validate incoming request (basically schema is there but it accepts any String in request, wsdl designers have their own reasons to do that to accept request from different sources and flexibility). But when the request is received, I validate that the child element of request wrapper is what we expect (using XPath for that). Now if the child element is not what expected, I'd like to throw Soap Fault with Client code and may be include error message that schema validation failed, request doesn't contain valid element.
I'm using Mule 3.3 and doing my XPath validation in <choice> element and I want to throw exception in <otherwise> block.
Is there a way to throw Soap Fault manually in mule flow and
How to add custom fault string. I'm not sure if an outInterceptor will solve the purpose as I'm not using schemaValidation attribute of <cxf:proxyService>.
Here is part of my flow
<http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://company.com/services/service" service="CompanyService" />
</http:inbound-endpoint>
<choice>
<when>.....</when>
<otherwise><!-- Here I want to throw Soap Fault ---></otherwise>
</choice>
<catch-exception-strategy>
<flow-ref name="generateErrorResponse" />
</catch-exception-strategy>
Since you are using a cxf:proxy-service you have complete control on the response. For example, if you add the following in your otherwise block, you'll be able to create whatever SOAP fault you want:
<expression-component><![CDATA[
message.payload = '<soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<faultcode>A code</faultcode><faultstring>A string</faultstring>'
+ '</soap:Fault>';
]]></expression-component>