Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Consume Token from Rest API and post that token and json to tHttpRequest

Dear All,

 

I am trying to develop a talend job that gets token from tRest component in json format where i tried to extract the token using tExtractJSONField and later I want to post a json(test.txt) along with the token to tHttprequest. But I am getting following error status,

 

{"status":"Failed","response":"Object reference not set to an instance of an object.","message":"Insert failed."}

But when i tried to replicate the same using postman it was working. Below I have attached screenshot of my talend job and my test scenarios which I did in postman for reference. Please assist me in providing work around for this error and let me know if you require further information.

 

Thanks in advance.

Labels (2)
30 Replies
Anonymous
Not applicable
Author

Yea, I have tired removing line from tlog and updated value of query parameters to row12.line. But still getting same error 0683p000009MPcz.png

 

uzix
Creator
Creator

hello,

 

im running out of ideias.....

 

you can pass all in the url , and test...theres some pages to urlencode decode......encode your payload

 

on trestclient use the full path and dont use the params

 

path in trestclient should be something like:

url: path + /?DETAILS=YOUR_ENCODED_PAYLOAD

 

check in postman a call okay and check on the right side -> "code" and select "http"

if possible post here the info..this way we can try to figure whats expected in a "good" call

 

 

 

 

 

Anonymous
Not applicable
Author

Thanks for your update @uzix .

 

Yea, I tried to check in postman, the code is as follows,

curl --location --request POST 'https://testwebapi.net/interface' \
--header 'Authorization: Bearer 93ToQiC-lnDKI2nALlCClcmbyw1Aa_iqWlOdmiog2pdZikkhyukuHJg' \
--data-urlencode 'DETAILS={"body":[
{"val1":"10580","val2":"82748","val3":"1226","val4":"155"},
{"val1":"2300","val2":"82548","val3":"1326","val4":"145"}
]}'

You mean, in tRestClient URL field do we need to update like this,

https://testwebapi.net/interface + "--header 'Authorization: Bearer " + globalMap.get("access_token") + "'" + "--data-urlencode 'DETAILS=" + row12.line + "'"

After trying above link in URL field I getting below error as follows,

Exception in component tRESTClient_1 (Copy_of_WebService_tRestClient)
javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: can't parse argument number:{"body":[
	at org.apache.cxf.jaxrs.client.AbstractClient.checkClientException(AbstractClient.java:638)
	at org.apache.cxf.jaxrs.client.AbstractClient.preProcessResult(AbstractClient.java:614)
	at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1115)
	at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1052)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:897)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:866)
	at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:334)
	at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:343)
uzix
Creator
Creator

hi,

 

dont put the token in the url, the token should be as it was. - check token pic.

also in advanced setting - select "log messages" - check pic log

url try like this:

"https://testwebapi.net/interface/DETAILS%3D%7B%22body%22%3A%5B%0A%7B%22val1%22%3A%2210580%22%2C%22va..."

 

 


log_messages.jpg
token.jpg
Anonymous
Not applicable
Author

Hi @uzix may i know what is the variables highlighted below we are passing

 

DETAILS%3D%7B%22 

uzix
Creator
Creator

hello,

this :

DETAILS%3D%7B%22body%22%3A%5B%0A%7B%22val1%22%3A%2210580%22%2C%22val2%22%3A%2282748%22%2C%22val3%22%3A%221226%22%2C%22val4%22%3A%22155%22%7D%2C%0A%7B%22val1%22%3A%222300%22%2C%22val2%22%3A%2282548%22%2C%22val3%22%3A%221326%22%2C%22val4%22%3A%22145%22%7D%0A%5D%7D

=

DETAILS={"body":[
{"val1":"10580","val2":"82748","val3":"1226","val4":"155"},
{"val1":"2300","val2":"82548","val3":"1326","val4":"145"}
]}

url encoded

 

search using your favorite search engine for url encode and url decode.

 

Anonymous
Not applicable
Author

Thank you @uzix . Let try using url end coded as well and post you updated.

 

Today I tried post to new web service for which token is not required as follows > in attached pic.

 

and test.txt have content as below,

"DETAILS"={"body":[{"val1":"10580","val2":"82748","val3":"1226","val4":"155"},
{"val1":"2300","val2":"82548","val3":"1326","val4":"145"}]}

 but while posting this data i am getting error as follows

{"status":"Failed","response":""The given key was not present in the dictionary.","message":"insert failed"}

But actually we have key named "Details" in the webservice. but the job throws error as above, If you have any idea on this error. Please update me.

 

Thanks in advance.

 

 

 


WithoutTokentHttpRequest.JPG
uzix
Creator
Creator

hello,

 

have you tried:

DETAILS={"body":[{"val1":"10580","val2":"82748","val3":"1226","val4":"155"},
{"val1":"2300","val2":"82548","val3":"1326","val4":"145"}]}

remove the " " in DETAILS 

Anonymous
Not applicable
Author

Finally I tried to post without key to the webservice and then it worked. Many Thanks @uzix 

uzix
Creator
Creator

great!!!!

 

glad you solve it!