I am trying to consume sales force rest api service in my java application.At that time i am getting this error.

"Server returned HTTP response code: 401 for URL: https://na1.salesforce.com/services/data/v26.0/"

I tested in advanced rest client with required values.It is giving output.While consuming same in my java code.It is returning this error

Please observe my source code

String resourceListUrl = "https://na1.salesforce.com/services/data/v26.0/"
url                    = new URL(resourceListUrl)
HttpsURLConnection con = (HttpsURLConnection)url.openConnection()

con.setRequestProperty("Authorization", "Bearer "+accessToken)
con.setRequestProperty("accept", "application/json")    

BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))

while ((resourceLine = br.readLine()) != null) {

Please help me.

Thanks Anuradha

  • 401 error refers to invalid access token, refresh your access token then try. salesforce.com/us/developer/docs/api_rest/… – SFIntegrator Feb 15 '14 at 10:15
  • i tried with same accesstoken in advanced Rest client browser.It is giving output.It is not returning any error. – Anuradha Feb 15 '14 at 10:28
  • Which Operating system your are running the code?, try replacing ! with \! in sessionID/accessToken – SFIntegrator Feb 15 '14 at 10:40
  • Hi Sandy,Thanks for reply.I tried as you told,but it is giving same error.My operating system is linux. – Anuradha Feb 15 '14 at 11:27
  • I am not very good at java, but i found this wiki.developerforce.com/page/DemoREST.java, see if helps. – SFIntegrator Feb 15 '14 at 11:43

Your Answer

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

Browse other questions tagged or ask your own question.