tHTTPRequest and parameters

Six Stars

tHTTPRequest and parameters

Hi all,

I have to upload a csv file using HTTpRequest component.

The API has the following specification:

Body Params

surveyId:
required
string

ID of the survey to import responses into

file:
required
file

A CSV file containing responses for import. [?]

 

I can mention the location of the csv in the "Post parameters from file" option. My csv contains headers and values.

How do I pass the survey ID ? since it is not in the query parameter but in the Body Parameter?

 

Also, I tried using Postman. It shows success message, but I dont see the csv values in the API.

 

Please help me out

Sixteen Stars

Re: tHTTPRequest and parameters

Try using the tFileFetch for this. It is badly named since it is not just for fetching files. This may require a bit playing about before it works. Take a look here for information on this component: https://help.talend.com/reader/MjIZDoU6r0vLbCpGh5GAcg/F4QsQrja9IQEa_kKqmBfNQ

Six Stars

Re: tHTTPRequest and parameters

Hi,

Thanks. I need not fetch the file from a URI. 

My situation is to upload a csv file to a site and mention the body parameters.

If I use tFilefetch, where do I mention the URI of my destination and what do I mention in the URI in the basic section.

Could you please elaborate

Sixteen Stars

Re: tHTTPRequest and parameters

Read the instructions and you will see that there is an "Upload file" option on the Advanced Settings page. You should be able to supply your parameters in the parameters section. Unless I have access to the API you are using, I cannot help anymore than this. You will need to experiment.

Six Stars

Re: tHTTPRequest and parameters

I have mentioned the required information based on the component details. Since tFileFetch is used to download a file and then upload it, I had confusion if it works when there is no need to download.Currently, i mentioned the endpoint in the URI and destination details as blank.

https://api.qualtrics.com/docs/import-responses is the api that i am referring to.

Sixteen Stars

Re: tHTTPRequest and parameters

Have tried it? You can upload with tFileFetch as well. Look for the upload file option.
Six Stars

Re: tHTTPRequest and parameters

Yes. I tried it. Also, which do you suggest:

tSystem component which runs the curl command as mentioned in the API specification or tFileFetch ?

Is it ok to just upload a file without mentioning the download option in tFileFetch?

Attached is the screenshot for reference. Is my configuration correct?

 

Sixteen Stars

Re: tHTTPRequest and parameters

That looks OK. Are you getting an error message?

Six Stars

Re: tHTTPRequest and parameters

This is the error that I get when i try to upload a csv

There isContinue_tFileFetch_1 an exception on: https://au1.qualtrics.com/API/v3/responseimports
java.lang.Exception: Method failed: HTTP/1.1 400 Bad Request
at vocalcomintegration.csv_0_1.csv.tFileInputDelimited_1Process(csv.java:757)
at vocalcomintegration.csv_0_1.csv.runJobInTOS(csv.java:1138)
at vocalcomintegration.csv_0_1.csv.main(csv.java:987)

Sixteen Stars

Re: tHTTPRequest and parameters

I'm afraid I think this is a learning curve you are going to have to go through. Using web services with ANY tool requires a fair amount of trial and error....with a lot of time spent filtering through errors, making slight changes and seeing if the errors change. My goto component for uploading files is the tFileFetch. However, if that doesn't work (and I can't get the error message to change), I will go to the tRESTClient or even the tREST. But if you do it via the tREST you will need to convert the file into a bytearray yourself and handle all of the complexities.

 

If I could have access to the web service you are using, I could probably get it sorted pretty swiftly, but doing it via trial and error via proxy is really difficult.

Four Stars

Re: tHTTPRequest and parameters

Do you happen to have an example job or a screenshot explaining how to change it to bitarray?

This seems to be a similar example as mine and the reason which I find this is not working is because its not able to send the body of the request. Hence 400 error. 

Sixteen Stars

Re: tHTTPRequest and parameters

I converted a file to a byte array by reading it using the tFileInputRaw and specifying byte array as the the read type. It will be returned as an Object, but you would just need to cast to a bytearray using a tConvertType.

 

Having said that, I am not entirely sure that would suit you. Did you try the link I sent you? That should work for you as you have total control over the code. Alternatively, did you try switching the "use cache to save the resource" on? Did that get rid of the defaultfilename.txt issue?

Four Stars

Re: tHTTPRequest and parameters

I did try the code snippet it throws 500 error while retrieving the data. 

Response{protocol=http/1.1, code=500, message=Internal Server Error.

A basic question- can https request be made over http client?

can I send a file with content type - application/x-www-form-urlencoded?

Because thats exactly what i am using in postman and its succeeding whereas in the code its not. 

Sixteen Stars

Re: tHTTPRequest and parameters

A 500 error is an internal server error. It is unlikely to be caused by how you called it....unless the server's error messages are pretty poor. You need to pay attention to the errors you get.

 

If you have it working using one tool you have to copy exactly how you did it with that tool in Talend. You have several components to work with. You have the tREST, tRestClient, tFileFetch or Java code to work with. You need to find a route that will allow you to exactly copy the way in which you have got it working elsewhere. By the way, you can use any content-type. Not all parameter options are offered to developers using drop downs. Sometimes you need to specify them using the parameter/header tables. 

Six Stars

Re: tHTTPRequest and parameters

Hi,

I tried tFileFetch and it seemed to error out because my API has specification to pass the Id and payload in body. But in tFileFetch I was not able to send ID as body.

What worked for me is tSystem. I used curl command and it worked file. I was able to upload the file.

Four Stars

Re: tHTTPRequest and parameters

Would you happen to share how were you able to accomplish this?

Six Stars

Re: tHTTPRequest and parameters

I used Curl command in tsystem to upload the file.