Make request to a rest API

One Star

Make request to a rest API

Hi all,
I'm new in Talend and I,m a bit lost for the moment, Smiley Wink
My problem is that I need to make request to an Rest API and download the response in a csv in my computer, are there an example of this issue in somewhere? I have been looking for some example and for the moment I haven't found any.
Thanks in advance
One Star

Re: Make request to a rest API

Hi
Welcome to Talend Community!
You can download the document and get some scenarios about tREST.
Hope this will help you.
Regards,
Pedro
One Star

Re: Make request to a rest API

Hi,
Thanks I saw this document before but when I have tried the example using an URL of yahoo quotes for example (if I put the URL in the browser , it's work fine) the talend log shows this:

Starting job tRestExample at 10:10 16/03/2012.
connecting to socket on port 3709
connected
Exception in component tREST_2
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:131)
at com.sun.jersey.api.client.Client.handle(Client.java:616)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:559)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:72)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:454)
at test.trestexample_0_1.tRestExample.tREST_2Process(tRestExample.java:516)
at test.trestexample_0_1.tRestExample.runJobInTOS(tRestExample.java:825)
at test.trestexample_0_1.tRestExample.main(tRestExample.java:693)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:218)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:129)
disconnected
... 7 more
Job tRestExample ended at 10:11 16/03/2012.
One Star

Re: Make request to a rest API

Hi
I create a job and connect to www.yahoo.com successfully.
tREST-->tLogRow.
Could you show me the URL?
The exception is "time out". I guess maybe there is something wrong with your network.
Regards,
Pedro
One Star

Re: Make request to a rest API

The URL that I've used is: "http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL&f=snl1" and Can you guess some posssible error in my configuration?
Thanks&Regards
Ivan
One Star

Re: Make request to a rest API

I think the problem is that I amrunning through a proxy, how can I configure my job for use tRest component? I'm trying to use tSet Proxy but it doesn't work.
Thanks&Regards
Ivan
One Star

Re: Make request to a rest API

Hi all,
Now I'm sure that the problem is that I'm working behind a proxy, because from my house (without proxy) it's works ok¡, anybody knows how to configure talend for connecting through a proxy, for using tRest component?
Thanks to all
Ivan
One Star

Re: Make request to a rest API

Hi Ivan
tSetProxy--OnComponentOk-->tRest
Did you encounter any error?
Regards,
Pedro
One Star

Re: Make request to a rest API

Hi Pedro
I have tried it and I hadn't found any error. Only the time out in the tRest component.
Regards,
Ivan
One Star

Re: Make request to a rest API

Hi
I have solved my problems with the proxy, but now I always receive a 401 response, I think is a problem with Autentication, how can I configure tRest authorization?
Thanks
Ivan
One Star

Re: Make request to a rest API

If you're using basic authentication, you'll add an HTTP Header called "Authorization" in the tRest configuration. The value for Authorization will be the string "Basic " (note the space after 'c') followed by a base64 encoded usernameSmiley Tongueassword value. Linux has a command base64 which will encode standard input or a file.
For example
Http Headers:
name value
"Authorization" "Basic OIhagjaphipagiyq=="