POST request with JSON data AND with authentication (OAuth 2)

Four Stars

POST request with JSON data AND with authentication (OAuth 2)

Using Postman, I can make a REST call with Auth AND raw JSON for the body.

 

However, in Talend,

- If I use the tRest component, I can create a post request with JSON data, but there are no authentication options.

- If I use the tRestClient component, I can use authentication (OAuth2), but then I don't have a "HTTP Body" field to send raw JSON data.

 

How do I make a REST call with Auth AND the "HTTP Body" field to send raw JSON?

 

Talend Studio 7.2.1


Accepted Solutions
Nine Stars JR
Nine Stars

Re: POST request with JSON data AND with authentication (OAuth 2)

You use the tRESTClient component, pass the body via the input schema in the input column "body" and use the authentication as provided by the component. You will have to build your JSON in a step before the tRESTClient component. If you have follow-up questions, please post them here.


All Replies
Nine Stars JR
Nine Stars

Re: POST request with JSON data AND with authentication (OAuth 2)

You use the tRESTClient component, pass the body via the input schema in the input column "body" and use the authentication as provided by the component. You will have to build your JSON in a step before the tRESTClient component. If you have follow-up questions, please post them here.

Four Stars

Re: POST request with JSON data AND with authentication (OAuth 2)

@JR thanks, I think I'm almost there. So I have a tWriteJSONField component which has "Output Column" of "body", then that feeds to tRESTClient component.  I logged the tWriteJSONField component and it seems to be outputting "body" correctly.

 

Then I send that over to the tRestClient component, but it looks like the body isn't being sent.  Can you take a look at the screenshots and let me know if this looks correct?

Nine Stars JR
Nine Stars

Re: POST request with JSON data AND with authentication (OAuth 2)

It certainly looks as if the request is being sent and that you get a response with HTTP status 200 back (no error). The response seems to be passed in the "string" column of the components output which is the case when the server handles the response as a string. The output column "body" is null because the server does not respond with structured output. As I do not know what the service you are calling actually does, I cannot say, if the response looks OK. But the fact that you get a 200 indicates to me that this works. If the local service you are calling (http://localhost) gives you any indication if it was called, you could look into the logs of the service to see whether it has been called or not for additional assurance.

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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 3

Read about some useful Context Variable ideas

Blog