Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

POST JSON with REST API

Hello,

 

I need to send data from a JSON file from Talend with REST API.
To verify that my file and my POST URL is working, I did the test on Postman without error, it allows to create new object in my tools.

 

I need it to work since Talend, because it will be industrialized later but I can not do it.

 

Here the contents of my JSON file:
"{
"path": "/Catalogue_Produits/Respiratoire/",
"elements": [
{
"type": "input",
"value": "Respi test 1 RESTAPIxxxx",
"name": "Denom",
"language": null
},
{
"type": "input",
"value": "RESPI test 1 RESTAPIxxxxx",
"name": "Nom_Data",
"language": null
},
{
"type": "select",
"value": "NouveauProduit",
"name": "PROCESSUS_SEL",
"language": null
}
],
"className": "Product",
"parentId": 98,
"key": "Respi3000",
"published": true,
"type": "object"
}"

 

Here the test ok on Postman:
0683p000009M2GK.jpg

 

I am new to Talend, but I tried to add the components:
tFileInputJSON => row => tRest_Client

The setting must be wrong because it does not work.

 

0683p000009M2TN.jpg

0683p000009M2RD.jpg

0683p000009M2TX.jpg

 

Can you help me ?

 

Thank you

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Your HTTP Body is empty, you should be passing the value that is sent from the tFileInputRaw. See my first Screenshot:0683p000009M2m6.png

 

Where 'row1' is the row leading from tFileInputRaw and 'content' is what represents the content of the file. (Clicking the row itself, then the component button will let you see what the schema is defined as)

0683p000009M2xr.png

View solution in original post

16 Replies
Anonymous
Not applicable
Author

Try using a tRest instead of a tRestClient to POST w/ a body. You can past the raw JSON directly in the HTTP body section (make sure to escape your double quotes though)

Anonymous
Not applicable
Author

it does not work, I added "\" in front of the quotation marks but it does not change anything :

0683p000009M2Th.jpg

 

The error :

 

0683p000009M2Tm.jpg

 

The code : 

 

0683p000009M2AD.jpg

 

Thank you for your help

Anonymous
Not applicable
Author

tFileInputJSON should only be used if you need to extract the columns from a JSON file. Because the body of the POST does not require that(i.e. you can send the raw text), then you don't have to use tFileInputJSON. You are getting those compiler warnings because you have extracted those values into a schema and tRest does not need them. Instead use a tfileInputRaw and pass the data into the body of the tRest.  I tested w/ a dummy api

0683p000009M2Tr.png

Anonymous
Not applicable
Author

Hello,

 

@evansdar, it works almost!

The data does not seem to have arrived in the correct format because I get an error.

I rechecked with POSTMAN and the contents of the JSON file is correct.

 

Would you have an idea?

Thank you

Anonymous
Not applicable
Author

@evansdar 

 

The error :

 

0683p000009M2x3.jpg

 

Perhaps the components InputRaw :

 

0683p000009M2x8.jpg

Anonymous
Not applicable
Author

You're still using tRestClient, swap to tRest.  You'll have to put a tFlowToIterate in between them to connect.

0683p000009M2xI.png

Anonymous
Not applicable
Author

@evansdar, I can not find the component tFlowTolterate in Talend

Anonymous
Not applicable
Author

@evansdar, I have found component.

 

The error continue :

 

0683p000009M2rG.jpg

Anonymous
Not applicable
Author

@evansdar 

 

The data are ok in log :

 

0683p000009M2kQ.jpg

 

Démarrage du job test10 a 14:53 06/02/2019.
[statistics] connecting to socket on port 3877
[statistics] connected
.--------------------------------------+----------.
| tLogRow_1 |
|=-------------------------------------+---------=|
|Body |ERROR_CODE|
|=-------------------------------------+---------=|
|{"success":false,"msg":"Invalid data"}|400 |
'--------------------------------------+----------'

.-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
| tLogRow_2 |
|=-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|content |
|=-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|{
"path": "/Catalogue_Produits/Respiratoire/",
"elements": [
{
"type": "input",
"value": "ALEX",
"name": "Denom",
"language": null
},
{
"type": "input",
"value": "ALEX",
"name": "Nom_Data",
"language": null
},
{
"type": "select",
"value": "NouveauProduit",
"name": "PROCESSUS_SEL",
"language": null
}
],
"className": "Product",
"parentId": 51,
"key": "ALEX",
"published": true,
"type": "object"
}|
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

[statistics] disconnected

Job test10 terminé à 14:53 06/02/2019. [Code sortie=0]