Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I have to use a GraphQL API in talend but I can't do it.
The goal is to get data from another API with a tjava, then i link the tjava with a tmap and to finish i use the tmap to do a request like : '{"query": "mutation { saveForm(formInput: {wasteDetails{name : ' + row1.wdName + '}) {id,wasteDetails{name}} }" }'
I try 3 differents way.
The first way was with tRest but we can't link a tmap to a tRest
The second way was with a tRestClient but I don't know what put in parameters in my url so I've had a http 500 errors
And the third way was with thttprequest but i don't know how to use the row of my tmap in my file for the post of the thttprequest
I hope I'm clear enough
Thank you in advance
First, connect your tRestClient to your tMap. You should see a body and a string column in your tMap output table. In your tMap output table's string column value expression, use this code....
"{\"query\": \"mutation\", { \"id\": \""+ row3.WTIERS +"\"}}"
......note the above code is abridged since the code you supplied was not complete. Note the "\" characters used to escape the quotes. You need to keep this in mind with Java String manipulation.
Once you have done this, you just need to make sure the tRestClient is configured with the correct endpoint and details.
You may want to test the JSON being produce by replacing the tRestClient with a tLogRow.
Can you send a screenshot of your job as it is at the moment? It sounds like you are using a Java API (via an imported Jar?) to get your data. You are then building an JSON String with your tMap and then trying to send that to a web service?
If that is correct, I would use a tRestClient to call GraphQL and ensure that your send the JSON via the string column (tRestClient needs either a string or body column....string for JSON, body for XML).
My job looks like that :
My tjava :
The result is a huge xml.
My tExtractXMLField_1 :
And my tmap :
The result of this job is :
These are the results I want to put in the graphQl api.
So i call an API, this API sends me a xml. With extractXML I take all the datas and they go in my tmap.
Now I have to put these datas in the tRestClient with a query like : '{"query": "mutation { saveForm(formInput: { id: '+ row3.WTIERS +', ....}) {id,wasteDetails{name}} }" }'
To do that I have to use a twritejson ?
First, connect your tRestClient to your tMap. You should see a body and a string column in your tMap output table. In your tMap output table's string column value expression, use this code....
"{\"query\": \"mutation\", { \"id\": \""+ row3.WTIERS +"\"}}"
......note the above code is abridged since the code you supplied was not complete. Note the "\" characters used to escape the quotes. You need to keep this in mind with Java String manipulation.
Once you have done this, you just need to make sure the tRestClient is configured with the correct endpoint and details.
You may want to test the JSON being produce by replacing the tRestClient with a tLogRow.
It works, thank you very much.
Hello Everyone,
I am facing the similar issue while performing the mutation operation
I was able to Query and receive the response as well
But while performing the mutation talend is throwing an error like below
Please find my Job Screenshots attached.....
It seems to suggest an unexpected character has been used in the JSON you are sending. Can you post the JSON here?
mutation { importEntities: {name: "ABC World"} {id} }
This is the JSON I am trying to POST
Thanks,
Archanalg
Hi rhall,
mutation{ upsertEntity(entity: { name:"ABC World"}) {id}}
when I try to post the same JSON in GraphQL Playground Link I am able to receive response,
Please let me know is there any specific component designed to handle GraphQL calls.
Thanks in advance,
Archanalg
This is bad JSON. It does not fit JSON standards. Test your JSON out here before posting it. It will help you identify what is wrong with it