You need to sign in to do that
Don't have an account?
vjoshi
REST API Sample Application
Hi,
I am trying to learn REST API through the sample application given on Force.com website. I have all the code integrated to NetBeans and I am able to put it to Tomcat server. Now, when I run the application through the browser, I get the link that says "click here to get data through REST/oauth" and then I get the salesforce login page too. But, when I type in the username and password, I get "error 310; too many redirects" and when I reload the page, I get error in doget method that says "addparameter arguments cannot be null.
Please help!
which sample app are you refering to?
From the description I'm pretty sure it's this one: http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_REST_API
Yes, it is the same application.
I had to change the code a little bit too. For example, I initialized all the parameters in OAuthServlet.java file into web.xml and removed the javax.servlet.annotation import as my netbeans said it does not exist. So, I removed the @WebInitParam initializers instead putting them in web.xml file. Also, I could not figure out where to put the init parameters for DemoREST.java file because I see a "url pattern" defined in the starting of that file. Also, what should be the servlet name for this file and should I put parameters for this file also in web.xml?
It sounds like you are using a servlet container that doesn't support the latest spec. The @WebInitParams only came in pretty recently.
I have changed it to work with web.xml. Is there a way I can use it with my current servlet container. I have tomcat 6.0.32 server with servlet 2.5. The @WebInitParams comes with servlet 3.0 I guess. And I am using Netbeans 6.9.1 version of IDE.
The REST API is not dependent on a particular version of the servlet API, but as you noticed, you will have to modify your web app config to make it work with init params etc.
I am trying to debug the code. I tried to print the value of tokenUrl in the browser from OAuthServlet.java file and I am getting this after putting in my username and password in the salesforce authentication page:
</OAuth>
I have commented out the redirect to /DemoREST in the last line to debug and am printing something on the browser to know whast loop the application enters.
Hi vjoshi,
There is some modification which you need to do in your code.
Please find below my code.It is almost the same but it worked for me.
I am still having one problem. For Contact, i am not getting the columns whichi want. All i am getting is Id and Name of the record.
In my last post ,i mentioned that i was not able to retrieve all the fields for the query.
I had to change the url variable.
String url = "https://na10.salesforce.com/services/data/v20.0/query";
Regards,
Chellappa
Hi,
Thanks for the reply.
One question. Are you not using the DemoREST.java file now? I mean there is no redirect to that file so I guess there is no need?
Also, I am unable to get the access_token and so I am getting this error when I run my application:
Oauhservlet.java JSONObject["access_token"] not found in doGet method.
I'm getting some of the other folks on the Evangelist team to run through the article and sample app to make sure everything works correctly etc. Stay tuned.
I was able to work the code and get some data (names) using the change suggested by Chellappa. This meant that I am not using the DemoREST.java file at all now. I have to do everything in OAuthServlet.java becauseit gives me "too many redirects" elsewise.
Also, after running the application a few times, I am now getting a blank page with no records after authentication step. After opening up the catalina.out log I found out that there was an error retrieving "recent items" from the JSON. It could not find it. I did not make any changes to the code so it was working before with the same name.