Trestclient sending json

One Star

Trestclient sending json

Hello,
I am trying to consume an API that needs as input a json file in talend.
I tried to send the json file in different ways, from the file directly, from the file and then using txmlmap and generate the structure of the json file in txmlmap and then send it to trestclient but I have difficulties
I have tested multiple scenarios but no success, the only way I was able to do it is by putting the json data that need to be sent using tfixedflowinput -> trestclient , by using tfixedflowinput it works fine
but when tried multiple scenarios I get each time either that is doesnt recognize the fields (error from the API saying that the fields are mandatory) or I receive during the compilation the error:A JSONObject text must begin with '{' at 1
when I use tfileoutputjson -> txmlmap -> trestclient and I receive A JSONObject text must begin with '{' at 1
the json structure seems fine, when I do a debug run, it seems that it sends the data to trestclient in xml format instead of json even though I mentioned in the trestclient that the input is in json because the API accepts only json format
I tried also using twritejsonfield -> trestclient, in the debug run it seems to send the correct json data in the right format but it still giving me the error A JSONObject text must begin with '{' at 1

the json data sent is:
{
"configurationId":"a125zy48451q",
"callLanguage":"EN",
"callId":"11111",
"client":{
"clientNumber":"0000021417001",
"clientExternalReference":"ABC123",
"name":"CompanyName",
"telephone":"111111111",
"faxNumber":"000000002",
"email":"info@domain.com",
"website":"www.domain.com",
"headOfficeNumber":"0000021417000",
"address":{
"street":"streetname",
"streetNumber":"10",
"streetBox":"3",
"zipCode":"10000",
"city":"CityName",
"countryCode":"100"
},
"bankAccount":{
"iban":"999999999999",
"bic":"BICCODE"
},
"declaration":{
"language":"0",
"rsz1":"000-111111-22",
"enterpriseNumber":"2222222222"
},
"invoiceData":{
"vatCode":"0",
"vatCountry":"FR",
"vatNumber":"22222222222",
"invoiceType":""
},
"clientData":{
"unionCode":"1",
"startDateSocialBalance":"02",
"endDateSocialBalance":"10"
}
}
}


can you please help
thank you
Community Manager

Re: Trestclient sending json

Hi
Read the data from json file and then use a tXMLMap to build the Document and select the content Type as 'Json' on tRestClient, if it can't still work, please let us know what's the parameter name and its data type required for your API.
Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Trestclient sending json

Hello Shong, 
thanks for your answer
I have tested your suggestion, it is giving me an error on trestclient error flow log that some fields are mandatory for the API, so it sends what I provide as data but it is not in the correct format to be read by the api
this is my flow:
tfileinputjson -main-> txmlmap -out-> trestclient -error-> tlogrow 
I then run in debug mode, the out row is in xml which is not accepted by the API and I believe this is from where comes the issue
is there a way to fix this please?
Kind regards
Thirteen Stars

Re: Trestclient sending json

Also check - what JSON object name for input for the tRESTClient
depending from API it could be Body or String
-----------
One Star

Re: Trestclient sending json

thanks vapukov for the example but weird, I can't seem to get it to work, I am definitely missing something but can't figure it out
I have tried what you have suggested but the weird is that the output of txmlmap is in xml format, anyway to control this to be in json?
thank you
Thirteen Stars

Re: Trestclient sending json

Think it will be better if You attach screenshots of Your components (with properties)
-----------