I am fairly new to Salesforce. I am writing a Java app that will make calls (either Soap or Rest) to the SF API. I think I need an oauth token to make the API calls? My company had a very simple PHP app working, but when I follow the URL it is using for oauth, I get this error:


This much is obvious: our PHP app redirects to our servers, whereas I am making the API calls from my local machine (a MacBook Pro). What sort of token can I get so I can make calls from my local machine? I need to be able to work locally so I can develop the software.

  • Create a Connected App in your Salesforce org and use your credential to login... connected app will allow you to login and get access token.., help.salesforce.com/apex/… and developer.salesforce.com/page/… visit these links and related to these topic... Thanks – amidstCloud Jun 1 '15 at 22:02
  • We already have a Connected App, I think. I'm asking how do I get an access token. – larry_rollio Jun 2 '15 at 13:08
  • Where do I go to set the CALLBACK URI for my connected app? – larry_rollio Aug 18 '15 at 18:41

If you just want to test out making calls to SFDC via the API, you can use the Session Id in an HTTP call. So if you were on NA1, you can query the standard API like this: https://na1.salesforce.com/services/data/v31.0/query?q=Select+Name+FROM+Account+LIMIT+2

To set the session token, add a Header with Key of Authorization and value of Bearer + your current session Id. You'll need to use a REST client if you want to test with a browser so you can set the Headers - I use the Postman extension

enter image description here

You can get the session Id via the Dev Console, or using a Chrome Plugin like Grey Tab

  • My account is with "na15", but if I put this in my browser: na15.salesforce.com/services/data/v31.0/… ,,, I get <errorCode>INVALID_SESSION_ID</errorCode> – larry_rollio Jun 2 '15 at 13:15
  • right - you can't just put that in a browser - you need to be able to set the Session Id, so you can use something like Postman do that (I added the link above) – BritishBoyinDC Jun 2 '15 at 15:11

There are many ways to login, but for simply testing the API, consider using a normal SOAP login. This is easier than using OAuth. You simply make the login call:

SoapClient binding = new SoapClient();
LoginResult lr = binding.login(username, password);
// lr.sessionId now contains a valid session.

Actual class names will depend on how the SOAP WSDL was imported, or if you're using a toolkit. You might look at the WSC, a pre-built JAR for using the API.

Should you decide to use OAuth, you'll need to choose a flow (web server, user client, or username/password), and follow the directions in Help & Training on their specific use. Except for username/password, all of the flows are more complicated than a simple SOAP login call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.