Download the PHP package chorton/salesforce-api-php-wrapper without Composer
On this page you can find all versions of the php package chorton/salesforce-api-php-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chorton/salesforce-api-php-wrapper
More information about chorton/salesforce-api-php-wrapper
Files in chorton/salesforce-api-php-wrapper
Package salesforce-api-php-wrapper
Short Description A library for interacting with the Salesforce REST API and managing the OAuth flow. Forked from https://github.com/crunch-accounting/salesforce-api-php-wrapper
License MIT
Homepage https://github.com/chorton/salesforce-api-php-wrapper
Informations about the package salesforce-api-php-wrapper
Salesforce PHP Library
A simple library for interacting with the Salesforce REST API.
Methods for setting up a connection, requesting an access token, refreshing the access token, saving the access token, and making calls against the API.
Getting started!
Installation: The package should be installed through composer and locked to a major version
Getting an OAuth Token:
With User interaction: You need to fetch an access token for a user, all followup requests will be performed against this user.
When having the username and password: To use this method you also need the security token to be appended to the password. Keep in mind this method is to be used as a replacement for the old API Key workflow.
Performing an action: Once you have an access token you can perform requests against the API.
The token will expire after an hour so you should make sure you're checking the expiry time and refreshing accordingly.
Setting up the Salesforce client
The client can be configured in two ways, you can call the static create method above passing in the login url and oauth details or you can use a configuration object as in the example below. This is useful when you need to resolve the client out of an ioc container.
The configuration data for the client is passed in through a config file which must implement \Crunch\Salesforce\ClientConfigInterface
For example
A config class is provided and can be used if needed. \Crunch\Salesforce\ClientConfig
The Salesforce client can then be instantiated with the config object and an instance of the Guzzle v4 client.
Authentication
Authentication happens via oauth2 and the login url can be generated using the getLoginUrl
method, you should pass this your return url for the send stage of the oauth process.
You should redirect the user to this returned url, on completion they will be redirected back with a code in the query string.
The second stage of the authentication can then be completed.
The token returned from here is the raw data and can be passed to the access token generator to make an AccessToken
.
Storing the access token
This access token should be stored. A method to store this on the file system is provided but this isn't required.
The example above uses the php session to achieve the same result.
The LocalFileStore
object needs to be instantiated with access to the token generator and a config class which implements \Crunch\Salesforce\TokenStore\LocalFileConfigInterface
The token store can then be created and used to save the access token to the local file system as well as fetching a previously saved token.
Refreshing the token
The access token only lasts 1 hour before expiring so you should regularly check its status and refresh it accordingly.
Making requests
Before making a request you should instantiate the client as above and then assign the access token to it.
Performing an SOQL Query
This is a powerful option for performing general queries against your salesforce data. Simply pass a valid query to the search method and the resulting data will be returned.
Fetching a single record
If you know the id and type of a record you can fetch a set of fields from it.
Creating and updating records
The process for creating and updating records is very similar and can be performed as follows. The createRecord method will return the id of the newly created record.
Deleting records
Records can be deleted based on their id and type.
Errors
If something goes wrong the library will throw an exception.
If its an authentication exception such as an expired token this will be as Crunch\Salesforce\Exceptions\AuthenticationException
,
you can get the exact details using the methods getMessage
and getErrorCode
.
All other errors will be Crunch\Salesforce\Exceptions\RequestException
, the salesforce error will be in the message