Monday, March 18, 2013

Salesforce OAuth & SOAP Integration in Python

We are publisher of a very successful SMS Magic App on Salesforce AppExchange (Check it Out). We are also one of the most reviewed app on AppExchange(Read Reviews).Customers see things working smoothly on SF App. Reason for that is, We have robust backend to support App WebServices. We are constantly doing R&D of various technologies to make User experience better.

In one such effort, We worked on implementation of Push integration with Salesforce Platform, We have started a project to implement OAuth 2.0 & SOAP WebServices in Python. Although Salesforce has very good documentation abt it, it only provides example of Implementation in Java and few folks have published their implementations for PHP5.

We have ourselves implemented OAuth 2.0 integration for Salesforce in Python. We want Salesforce community to get benefitted from it as we have also benefitted from SF Communities solutions in the past, so We want to publish this solution to open world so that community gets benefitted from it.
Generally when developer want to Interact with Salesforce Org from their Products sitting outside of Salesforce like Creating New Records, Reading  records and Updating existing record of Standard Or Custom Objects. There are two ways to achieve this:
  1. Using WebService: For WebService Approach, We chose - salesforce-python-toolkit from here. This toolkit uses SOAP API to make various operations like create, delete, update, upsert, etc. on Salesforce Org, using WSDL files provided by Salesforce. You can see for all the possible operations on SF objects in wsdl files. Calling a webservice with SOAP will need the actual credentials. Click here to read more about SOAP API
  2. Using OAuth: They had explained things really well here. But the API was in Java. We started searching for a python API for for Salesforce objects. There was none. In fact I think nobody had written it using python. So instead of searching more, we wrote a module of our own.We needed to use special package in Python which support PATCH method.
OAuth : For a Salesforce's client application to access user information, the user has to authorize that application to use its information. When user authorizes the application a refreshToken is sent to the application. This application then can access and modify user's information using this refreshToken, it doesn't need user's login and password. For Upsert/update operation, Salesforce uses PATCH method instead of POST method. Python has one library to send request using PATCH method. you can install it from here (Install Request Package of Python)

Salesforce has good OAuth 2.0 documentation, you can read it here.

You can Download full source code from Git: Source Code

Feel free to ask any question for any clarification.

Author : Hussain Tamboli, works as a Software Developer with Screen-Magic. He loves hacking and solving tough problems. You can follow him on Twitter @hussain_tamboli, You can catch the_dark_knight on IRC channels.

No comments:

Post a Comment