Accessing SalesForce.com using Web Services and Scripting – Part 1

Many of the modern Web platform offer Web Services API’s to access their data.

One of them is SalesForce.com. I choose this example because it has a huge global audience and a well documented Developer Guide.

Before starting your scripting exercise you need to plough through the extensive developer manuals. Which is the lease fun part. Therefore I summarized it all for you to give you all a head start. Winking smile

SF.com has a number of Web Services Protocols as well as a number of authentication methods using the OAuth 2.0 protocol.

On top of that you can start developing in SF.com using APEX

What is APEX

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_what_is_apex.htm

Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform server in conjunction with calls to the Force.com​ API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.

1. Web Services Protocol

You can use the SOAP protocol or you can use the REST protocol, to access to the web services API.

Both have different ways of dealing with this in you programming / scripting environment.

REST API

https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_REST_API

The REST API is designed to be easily accessible from any programming language – once you understand the basic concepts of the API, you will be able to apply them to PHP, Ruby, .NET, or any other environment.

SOAP API

https://developer.salesforce.com/docs/atlas.en-us.200.0.api.meta/api/sforce_api_quickstart_intro.htm

Use SOAP API to create, retrieve, update or delete records, such as accounts, leads, and custom objects. With more than 20 different calls, SOAP API also allows you to maintain passwords, perform searches, and much more. Use SOAP API in any language that supports Web services.

Choosing a WSDL

· Force.com Enterprise WSDL—This API is for most enterprise users who are developing client applications for their organization. The enterprise WSDL file is a strongly typed representation of your organization’s data.

Note the following when generating the enterprise WSDL:

· If new custom fields or objects are added to, renamed, or removed from your organization’s information, you need to regenerate the WSDL file in order to access them.

· The generated WSDL contains the objects and fields in your organization, including those available in the selected versions of each installed package. If a field or object is added in a later package version, you must generate the enterprise WSDL with that package version to work with the object or field in your API integration.

· Force.com Partner WSDL—This API is for Salesforce partners who are developing client applications for multiple organizations. As a loosely-typed representation of the Salesforce object model, the partner WSDL can be used to access data within any organization.

More API’s and which one to chose ?

https://developer.salesforce.com/docs/atlas.en-us.200.0.api.meta/api/

2. Authtentication Protocol

SF.com uses OAuth2.0 protocol for users to authorize applications, to access Force.com resources (via the Force.com REST and SOAP Web Service APIs).

More info :

http://oauth.net/

The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service.

More info on OAuth 2.0 authorization framework :

https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com

1. Obtaining an Access Token in a Web Application (Web Server Flow)

2. Obtaining an Access Token in a Browser or Native Application (User-Agent Flow)

3. Obtaining an Access Token using a JWT Bearer Token

4. Obtaining an Access Token using a SAML Bearer Assertion

5. Obtaining an Access Token using a Web SSO SAML Assertion

6. Obtaining a Token in an Autonomous Client (Username and Password Flow)

For our scripting purpose we are going to use the Autonomous Client method.

clip_image002

SF.com Configuration Settings

Before Starting you need to do some configurations in SF.com

1. User

On the user level you need to trigger a Security Token, that we will use in the client application

clip_image004

2. SOAP API

Generate your WSDL file ENTERPRISE or PARTNER

clip_image006

3. REST API

Create a new APP Config and setup the OAuth access parameters.

If you use a Client Application (no Web Interface) you don’t need to set the Callback URL.

Just fill in some dummy data.

image

Once you have configured the new APP, you can read out the CLIENT CONSUMER KEY and the CONSUMER SECRET

This you will need later on when configuring the Client Application Access.

4. Object Model

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_majors.htm

Next you need to get acquainted with the SF.com Object Model / Data Model in order to run the proper Queries definitions.

clip_image002[5]

OK, so now you are ready to get started if you have made up your mind which of the options you want to chose.

Powershell Examples :

1. SOAP API : See here

2. REST API : See here

Out of experience the REST method is much faster.

More info here:

http://danlb.blogspot.be/2010/10/salesforcecom-rest-api.html

As you can notice is that you go a long way just using a Scripting environment.

Enjoy

Smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: