I have a public website in PHP where users can login, create accounts, update profiles...

I need the site to create, read, update and delete data in Salesforce. Leads, contacts and other custom objects. It's fine to allow the site to do all this operations in Salesforce and control user permissions from the site's database.

At first I thought the REST API would be great, except that it seems to require a (Oauth) login from a Salesforce user.

What's the best way to achieve this?

  • 1
    Be aware that you are approaching a violation of the Salesforce Master Service Agreement, specifically sections 4.2 and 4.4(g). While it is technically possible to do what you're attempting, you might lose your ability to use the services provided by Salesforce entirely by doing so.
    – Mark Pond
    Apr 15, 2015 at 22:44
  • Mark, integration with a public website via Salesforce APIs is an extremely common use case. How is it a violation of the MSA? Apr 15, 2015 at 23:03
  • Thank you. I'll try to test the solutions this weekend and add comments.
    – Osvaldo
    Apr 16, 2015 at 15:28

5 Answers 5


There are a few ways to achieve what you want. The first option is to use, as you mentioned the REST API. You will have a user in Salesforce that has administrative rights. The documentation on how to connect to an endpoint in Salesforce can be found here. I know some of the examples are not in PHP, mostly C# and Java but you could work out what it's trying to do.


I recommend having a look at Bulk API and using it if you are planning to perform operations on Salesforce's database. Salesforce being a cloud application in a multi tenant environment you need to be aware of the limits and you need to insert or upload data in batches.

Second option will be to use Data Loader or a tool like DBamp, tools that by default use Bulk API, which connects from your database to Salesforce and then you can perform different updates, inserts using SQL statements which might be easier for you to start with.

You could also use SOAP API where you consume a WSDL and then perform operations to Salesforce. Here you can find documentation for SOAP API

There is also and I encourage you to look at, the Force.com PHP Toolkit which fulfills a lot of your requirements without you trying to re-develop.

Hope it helps and good luck!


There are two facts related salesforce that you should consider before taking a decision.

1) Salesforce pricing is license based. The more licenses(users that logs into salesforce) you purchase, more will be the amount you need to pay. To overcome this you can use one API user login to connect with Salesforce from php(probably Force.com PHP toolkit). But then you might hit API limit.

2) Salesforce API limit is comparatively big. But if you are looking for real time integration and every day there is lot of transactions, you might have to buy some extra API calls(you can purchase it from salesforce)

If you are open to migrating your php application to Heroku, salesforce offers connectors to sync data between Heroku Postgres database. You can try this option also. Heroku will avoid some server maintenance effort.

  • Can you point an API costs page?
    – Osvaldo
    Apr 16, 2015 at 15:32
  • To get a correct cost, you might have to contact Salesforce support team. There is no public documentation from Salesforce explaining exact additional cost of extending API limit.
    – Victor
    Apr 16, 2015 at 16:28
  • Check help.salesforce.com/… . This gives an overview of API limits
    – Victor
    Apr 16, 2015 at 16:48

Another way which I'm not seeing here is utilizing Salesforce sites. The idea here is to build a site with a path - this requires no authentication to access, obviously there is a security risk there; then the API is exposed through that site via a guest user license.

I've tried this myself to build a form on a site - I even had it search if the provided email exists in the database and matched the new record to the identified record. There are a few articles, forum posts, and blog posts:

  1. Pat Patterson SFDC Developer Blog
  2. Public API SFDC Developer Forum
  3. Public API Stackexchange Post
  4. Public API Stackexchange Post 2
  5. Webservice without Authentication SFDC Developer Forum

In the site permissions provide access to any custom APIs built in apex or any standard/custom objects. For your endpoints, use this format: {Site_URL}/services/apexrest{URL_mapping}. This should provide a way to build a public API using Salesforce; similar to their web-to-lead feature. I haven't tried it, but I don't see why you wouldn't be able to access the standard API as well.

  • Thank you. I'll try to test the solutions this weekend and add comments.
    – Osvaldo
    Apr 16, 2015 at 15:29
  • OP stated that they need to update some of the core CRM objects like Leads and Contacts. The public Sites User's license type explicitly forbids that; Salesforce's position is that you cannot use Sites functionality to directly update Lead/Contact records. Here's an example thread discussing this issue: developer.salesforce.com/forums/… There may be some workarounds on this (like Apex REST), but I'd be careful with those as Salesforce's official licensing position is that customers are not permitted to use Sites to update these objects.
    – jkraybill
    Apr 20, 2015 at 5:13
  • @jkraybill thanks for the concern, but personally I don't believe it warrants a down vote. If Pat Patterson created a post on the developer forum explaining how to do this, I think it's more on the side of do it at your own risk and you lose audit functionality. Further, the OP stated he's looking for another way besides oauth to access - this answers that question. Finally SFDC has rate limits of 1000 calls/day x number of user licenses. This also limits the amount of calls to be made so it is not cheating sfdc out of money. They could absolutely limit this function if they wanted as well.
    – zainogj
    Apr 20, 2015 at 13:43

Instead of using a username/password or OAuth for an API user you might try SF's mutual authentication. Outside SF this is mostly known as Client Side Certificate Authentication feature. This secure feature offers quick access without credentials to any SF API, ie. the REST Partner API.

You do require a certificate signed by one of these authorities: http://sforce.co/1H8CzKR

  • Thank you. I'll try to test the solutions this weekend and add comments. Can you please point to a page that documents how is this implemented, ideally with code, preferably PHP.
    – Osvaldo
    Apr 16, 2015 at 15:31

You can create ApiUser in SFDC instance and use it for login via API


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .