You need to sign in to do that
Don't have an account?
Anindya Chattopadhyay
Calling Rest API from WordPress site
Hi there:
I am really new to this big Salesforce world. One of the requirement for us is to create Salesforce entites remotely from our WordPress site. The only way I can think of right now is to use JavaScript.
Can anyone please tell me how to do it using REST API? I found some documentation on https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit. However I am not sure how to approach here. What values do I need to supply for var clientId , var redirectUri and var proxyUrl? Is there any other way?
Any help will be much appreciated.
Thanks
Anindya
I am really new to this big Salesforce world. One of the requirement for us is to create Salesforce entites remotely from our WordPress site. The only way I can think of right now is to use JavaScript.
Can anyone please tell me how to do it using REST API? I found some documentation on https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit. However I am not sure how to approach here. What values do I need to supply for var clientId , var redirectUri and var proxyUrl? Is there any other way?
Any help will be much appreciated.
Thanks
Anindya
2. When you have any intermediate proxy servers in your organization, and users use the proxy in web browser, request goes via that proxy server to internet. In this case you may need to pass on the proxy server's URL in that parameter. If you dont have any proxy servers, then you shall not pass the proxyURL parameter and it's an optional one.
Let me know if it helps
All Answers
Basically you need an access_token with every request to get salesforce data. In order to obtain one, you need to first authenticate with your Salesforce organization. This can be done through OAuth, which is recommended way instead of hardcoding credentials.
You must create a 'Connected app' in salesforce by registering your wordpress application details. By doing so salesforce creates a Client ID and Client Secret for you application. When you first authenticate with salesforce, provide these 2 values along with the request. This will redirect you to Salesforce authentication page where, upon successful authentication, you will be redirected to a web page which you mentioned in 'redirectURI' parameter(This can be you initial page where you made the authentication request in you application).Once redirected, you'll have an additional parameter in the response, authorization code.
Checkout the documentation below for a detailed walkthrough.
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm
Best regards,
Sathish Balaji
Hi Sathish:
Thanks. I got some idea after going through that. I also found the following link partciularly useful:
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_oauth.htm
So we can either use OAuth or Session ID, the later one requiring username and password.
Couple of more queries:
1. Does the callback URL relate to the external web page from where I am calling the Salesforce API using JavaScript?
2. I am still not sure what's proxyUrl?
I believe if I need to write managed code (Java, C# etc.) to build a client to consume the API, I don't need the proxyUrl?
I hope I understood it right. Any help will be much appreciated.
Thanks and regards,
Anindya
2. When you have any intermediate proxy servers in your organization, and users use the proxy in web browser, request goes via that proxy server to internet. In this case you may need to pass on the proxy server's URL in that parameter. If you dont have any proxy servers, then you shall not pass the proxyURL parameter and it's an optional one.
Let me know if it helps
var client = new forcetk.Client(clientId, loginUrl, proxyUrl);
made me think that proxyUrl is mandatory. So in my case, the above line will look like this:
var client = new forcetk.Client(clientId, loginUrl);
Hope I made sense.
Regards,
Anindya
var client = new forcetk.Client(clientId, loginUrl,null);
Got it.
Thanks again!
Anindya
https://developer.salesforce.com/forums?id=906F0000000Af2IIAS
alternatively, you can try with an integration plugin like: https://sfplugin.com/