Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

API Call get the response in JSON and extract the data

avatar
Contributor

@Matt Burgess I need one help I have one rest API and that API return the response in JSON format. In that JSON one attribute is Certificate and that attribute we need to save in the txt file. Could you help on that

details are as following :

https://hpe-api.sabacloud.com/v1/login

site:NA2PRD0002

password:restWS0808

user:WS_ADMIN

1 ACCEPTED SOLUTION

avatar
Master Guru

@Shakeel Ahmad

You need to use InvokeHTTP processor to get response back from the API.

InvokeHTTP Configs:-

change the Remote URL property value to your url that gives back you required response.

45773-invokehttp.png

Change the Username,Password property values also.

In this invoke http processor will get the JSON response and then you need to use

Evaluate Json Path processor:-

45774-eval-json.png

if you are going to extract only one attribute then you need to add new property that matches with the Json attribute.

Example:-

1.If your json response is flattened as like below

{
    "id": "1",
    "Certificate": "HCC"
  }

Then the output of EvalJsonpath processor with above Configs would be

HCC

2.If your json response is like below

{
  "data": {
    "id": "1",
    "Certificate": "HCC"
  }
}

Configs of EvalJSON Processor:-

45776-evaljson.png

As you can see above screenshot i have changed the Certificate Property value as my JSON response Certificate is inside the data list.

so i have matched the Certificate attribute using $.data.Certificate which will result the output as

HCC

You need to change the Certificate property value as per your JSON Response.

Once you get output from the EvaluateJSONPath processor the results are stored in a File, You can store the file using PutFile(or)PutHDFS...etc

Flow:-

45778-flow.png

1.GenerateFlowFile Processor //Schedule to trigger InvokeHTTP processor
2.InvokeHTTP //Change the url,username,password property values and connect Response relation to EvalJsonPath
3.EvalJsonPath //add Certificate matching property value and connect matched relation to next processor
if you are going to store the result into HDFS or Local then
4.PutHDFS(or)PutFile //to store the output file from EvalJsonPath to Local (or) HDFS

View solution in original post

2 REPLIES 2

avatar
Master Guru

@Shakeel Ahmad

You need to use InvokeHTTP processor to get response back from the API.

InvokeHTTP Configs:-

change the Remote URL property value to your url that gives back you required response.

45773-invokehttp.png

Change the Username,Password property values also.

In this invoke http processor will get the JSON response and then you need to use

Evaluate Json Path processor:-

45774-eval-json.png

if you are going to extract only one attribute then you need to add new property that matches with the Json attribute.

Example:-

1.If your json response is flattened as like below

{
    "id": "1",
    "Certificate": "HCC"
  }

Then the output of EvalJsonpath processor with above Configs would be

HCC

2.If your json response is like below

{
  "data": {
    "id": "1",
    "Certificate": "HCC"
  }
}

Configs of EvalJSON Processor:-

45776-evaljson.png

As you can see above screenshot i have changed the Certificate Property value as my JSON response Certificate is inside the data list.

so i have matched the Certificate attribute using $.data.Certificate which will result the output as

HCC

You need to change the Certificate property value as per your JSON Response.

Once you get output from the EvaluateJSONPath processor the results are stored in a File, You can store the file using PutFile(or)PutHDFS...etc

Flow:-

45778-flow.png

1.GenerateFlowFile Processor //Schedule to trigger InvokeHTTP processor
2.InvokeHTTP //Change the url,username,password property values and connect Response relation to EvalJsonPath
3.EvalJsonPath //add Certificate matching property value and connect matched relation to next processor
if you are going to store the result into HDFS or Local then
4.PutHDFS(or)PutFile //to store the output file from EvalJsonPath to Local (or) HDFS

avatar
Contributor

Thanks Lot @Shu for your details description explanation. My Flow now look like as below .Thanks Lot

45792-fullflowofapiconfiguration.png