Issue to extract the token from the body

Five Stars

Issue to extract the token from the body

Hello,

I have an issue to extract the token value from the Body.In my API Rest I am getting the body completely and I am trying to extract just the token from it but I couldn't suceed.t1.PNG

t4.PNGtmap and txmlmap:t2.PNGt3.PNGt5.PNG

t6.PNG

As you can see the first screen capture that I am getting oneline but after it passes through composant textractxml field 0 line is inserted.As I am new to API rest in talend I don't much about the functionalities.I know there is something missing in the composant tExtractXMLField but I couldn't find it.If you have any ideas please comment it below.

Six Stars

Re: Issue to extract the token from the body

I'm not too great with XML so what i tend to do in development is put a tLogRow after each step just to make sure the data looks how i expect it to look at each step. You'll probably find that the tExtractXML component isn't doing what you expect. 

Seven Stars

Re: Issue to extract the token from the body

Hi !

 

The easiest way to achieve that is to put your XML example in a file, and then in XMLMap, on the left pane, right-click on your entry "body", and choose "Import from File". It will build you the structure of your XML.

 

On the right pane, add a simple String field and drag-drop the attribute (it displays under your field, starting with an @ ).

 

So :

TRest =>tXMLMap=>tLogRow 

 

That's it, no need for further headache Smiley Happy

 

Sincerely,

Five Stars

Re: Issue to extract the token from the body

Thanks for your reply,

t1.PNGt2.PNG

I did as you proposed but how to get the elements from the body when its not recogonised in the tXMLmap composant?

or the other way could be to use the composant textractXML but I dont know exactly what to fill in the Xpath loop and in the mapping Xpath.

If you have some ideas please let me know.

Have a good day,

Tags (5)
Six Stars

Re: Issue to extract the token from the body

What's the format of the Body which is output from the tRest component? If token is not an XML node then the tExtractXML component won't be able to find anything. It might be better to convert the Body to a string then in a tJavaRow component strip out the token and save it to use elsewhere.

 

For example if the format of the Body was

 

token=ABC123456

 

then in a tJavaRow you could do something like this

 

//create a sting to work with
String token = ""; //check it's not null first if(!Relational.ISNULL(input_row.body) && !input_row.body.equals("")){ //get a substring from the offset of token= to the end of the string token = input_row.body.substring(input_row.body.indexOf("token=")+6, input_row.body.length()); } //put the token into a global variable to recall elsewhere globalMap.put("Token", token);
Five Stars

Re: Issue to extract the token from the body

the token looks like this

token="IEllQMy6Qmh6VEB3EsdoNGHfU9C3eivv3Dw"t10.PNGt11.PNG

Thanks for your reply I tried it but its not working ,because it couldn't identify the column 'token'.But its okay that its not the case that token is null.

 

The output format of the body is a string.The token is never null because the I have verified in the postman as well.The issue is that the textractxml could not identify the values of the string.So I think I should make it understand the string with the xpath loop and the query xpath.

Tags (5)
Highlighted
Five Stars

Re: Issue to extract the token from the body

Hello,

Thanks for the solutions you have proposed me but the issue isn't solved yet.

Your solutions are still welcome.

 

Thanks in advance for your replies,

Tags (5)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Talend Cloud Developer Series – Deploying First Job to Cloud

This video will show you how to run a job in Studio and then publish that job to Talend Cloud

Watch Now

Talend Cloud Developer Series – Fetching Studio License

This video will help someone new to using Talend Studio get started by connecting to Talend Cloud and fetching the Studio License

Watch Now

Talend Cloud Developer Series - Introduction

The Talend Cloud Developer Series was created to give you a solid foundational understanding of Talend’s Cloud Integration Platform

Watch Now