Eight Stars

tRestClient response received is not in correct format

We are trying to use tRestClient to get corresponding responses from a REST webservice and extract the data and bring to our use. 

But the response when received is a bit off as 'body' is received as null where-else we have the complete content of response from the server end in 'string'.

'HTTP Method' is 'GET'

'Accept Type' is 'Any'

 

The response received when printed using tLogRow -

|statusCode|body|string |
|=---------+----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=| |200 |null|{ "items" : [ { "Salutation" : null, "FirstName" : "Jessica", "MiddleName" : null, "LastName" : "Ashley" ], "count" : 10, "hasMore" : true, "limit" : 10, "offset" : 0, "links" : [ { "rel" : "self", "href" : "https://///emps", "name" : "emps", "kind" : "collection" } ] }

Let me know if any more information is required on this, thanks in advance for any help.

Platform: Talend Open Studio for Data Integration Version: 6.5.1

15 REPLIES
Fifteen Stars

Re: tRestClient response received is not in correct format

What are you expecting back? If you are expecting XML, you will need to show us your API and configuration of your Talend component. If you are expecting JSON, this is JSON and it will always be a String. The Body is a document and that is XML.

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

I am expecting the response to be in JSON format as at the next step I am using tExtractJSONFields to extract different individual nodes from the response content.
I was expecting the response to be received in 'Body' rather than 'String' that's why at tExtractJSONFields I am mention JSON field to - 'Body' and then using JSONPath query and other mappings.
Should I change the same to 'String' at tExtractJSONFields and give it a go?

Fifteen Stars

Re: tRestClient response received is not in correct format

Body is named poorly to be honest. It is hardcoded as a Document. This is an XML format. You need to change your receiving component to accept the String field. JSON (while referred to as a document by people, is actually a String).

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

Thank you @rhall_2_0.

I did the changes so that tExtractJSONFields read the JSON response from JSON Field "string". Now the rpoblem is whatever I use to read "JsonPath" or "XPath" this would not extract anything out.

 

So, got the response and stored it in a json file and used tFileInputJSON and did a "JsonPath" read of the data with the same Loop Json Query & Json Query which gave the output pretty much nicely.

 

tRestClient-1.JPG

 

Fifteen Stars

Re: tRestClient response received is not in correct format

You need to show the output you get, you also need to show your configurations of the components (JSON ones). There is nothing wrong with Talend here as I do this all the time, there will be an issue with your configuration. I can't help unless you show me the config though

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

That's what I had also suspected as the response when put on a file and parsed worked fine.

Here you go the details, let me know if this would be enough or more info would be required.

tRestClient-2.JPG

Fifteen Stars

Re: tRestClient response received is not in correct format

I'm afraid I cannot see the images clearly enough. But something has raised a suspicion as to whether your previous example shows the same JSON being processed by the same code. The first job shows 1 row from the service being converted to 6 rows. This can ONLY be because of the looping finding 6 loops. SO that is working. But in the second example you have 1 row coming out. This means either the JSONPath expressions are not the same or the data is not the same.

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

My bad, I had tried something out in between the posts and posted that but not the original one for which the conversation started.

The below are for the process which has 1 row from the service being converted to 6 rows.

Let me know if the screenshots are bit clear now - 

tRestClient-2.JPG

tRestClient-3.JPG

 

Fifteen Stars

Re: tRestClient response received is not in correct format

Your JSONPath looks wrong. Why are you not setting the Loop to $.items[*] ?

 

When I asked for the JSON I meant as text. That way I could quickly knock something up to test. Also, if you have a working solution and one that is not, it would be useful to see both. I suspect that you are using the "JsonPath without Loop" option in the file based one.

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

I have already tried using $.items[*], which resulted in this -

tRestClient-5.JPGtRestClient-6.JPG

This is the working one where I referred to the json file and did the extract - 

tRestClient-5.JPGtRestClient-6.JPG

 

Eight Stars

Re: tRestClient response received is not in correct format


@rhall_2_0 wrote:

JSON as text -


{
	"items": [{
		"Salutation": null,
		"FirstName": "Jessica",
		"MiddleName": null,
		"LastName": "Ashley",
		"PreviousLastName": null,
		"NameSuffix": null,
		"DisplayName": "Jessica Ashley",
		"SalutationLOV": [{
			"LookupCode": "DR.",
			"Meaning": "Doctor"
		}],
		"photo": [],
		"assignments": [{
			"AssignmentName": "Junior Designer",
			"PersonTypeId": 300000000180948,
			"GradeLadderId": null
		}]
	},
	{
		"Salutation" : null,
		"FirstName" : "Emily",
		"MiddleName" : null,
		"LastName" : "Merced Melendez",
		"PreviousLastName" : null,
		"NameSuffix" : null,
		"DisplayName" : "Emily Merced Melendez",
		"SalutationLOV": [{
			"LookupCode": "DR.",
			"Meaning": "Doctor"
		}],
		"photo": [],
		"assignments": [{
			"AssignmentName" : "Hand Assembler",
			"PersonTypeId" : 300000000180948,
			"GradeLadderId": null
		}]
	}],
  "count" : 2,
  "hasMore" : true,
  "limit" : 2,
  "offset" : 0,
  "links" : [ {
    "rel" : "self",
    "href" : "https://xxxx-xxxx.xx.xxx.xxxxxxxxxxx.com:443/xxxxXxxx/resources/11.12.1.0/emps",
    "name" : "emps",
    "kind" : "collection"
  } ]
}
Fifteen Stars

Re: tRestClient response received is not in correct format

Can you attach the tLogRow to your tRestClient component and send me the output? I have just tested this using a tJavaFlex (to emulate the response of the service) and the same config (exactly) as your setup (where you use the tRestClient). I got the following response....

 

.---------------------+---------+-------------------.
|                     tLogRow_1                     |
|=--------------------+---------+------------------=|
|Fullname             |Firstname|Description        |
|=--------------------+---------+------------------=|
|Jessica Ashley       |Jessica  |["Junior Designer"]|
|Emily Merced Melendez|Emily    |["Hand Assembler"] |
'---------------------+---------+-------------------'

I suspect that the output from your service might be slightly different from what is in your file. It is easy as a developer to inadvertently modify your dataset when trying out things like this. But your JSONPaths work perfectly as you've shown in your previous post.

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

Here you go -

tRestClient-7.JPG

 

The output - attached (due to character limitations)



 
Fifteen Stars

Re: tRestClient response received is not in correct format

I have tested that data and it works perfectly for me. The only thing left for me to test would be the actual web service, but I am assuming that you cannot give that to me to try. I am beginning to think that there may be something corrupt in your job. It is only a small job, can you rebuild it from scratch and test that? This certainly isn't normal for Talend, but can happen under some circumstances.

Rilhia Solutions
Eight Stars

Re: tRestClient response received is not in correct format

Thank you @rhall_2_0 for your patience thus far.

Yes indeed the web service is authentication based and I am afraid that I couldn't share Smiley Sad

I am puzzled and out of ideas on exactly what has been happening that the response from tRestClient couldn't be extracted using tExtractJsonFields. 

Let me try to rebuild the job, maybe a new job else would try in some other system too. Will keep posted for any break-through.