kestra-io / plugin-fs

https://kestra.io/plugins/plugin-fs/
Apache License 2.0
6 stars 7 forks source link

http.Request POST response body returns request body instead #121

Closed wrussell1999 closed 5 months ago

wrussell1999 commented 6 months ago

Expected Behavior

When you make a POST request with io.kestra.plugin.fs.http.Request using a JSON body, you can access the response body through {{ outputs.task_id.body }}.

Actual Behaviour

When you make a POST request and access the output, the body is the same as the property body used to make the request.

Steps To Reproduce

Run the following flow:

id: http_request_example
namespace: example
description: Make a HTTP Request and Handle the Output

inputs:
  - id: payload
    type: JSON
    defaults: |
      [{"name": "Will", "job": "Developer Advocate"}]

tasks:
  - id: send_data
    type: io.kestra.plugin.fs.http.Request
    uri: https://reqres.in/api/users
    method: POST
    contentType: application/json
    body: "{{ inputs.payload }}"

  - id: print_status
    type: io.kestra.core.tasks.log.Log
    message: "{{ outputs.send_data.body }}"

The output will look like this (the same as the request body): image

Documentation for the API

Postman is able to get a response body that matches the documentation. Screenshot 2024-04-19 at 15 38 02 Screenshot 2024-04-19 at 15 38 16

Environment Information

Example flow

Example 1

id: http_request_example
namespace: example
description: Make a HTTP Request and Handle the Output

inputs:
  - id: payload
    type: JSON
    defaults: |
      [{"name": "Will", "job": "Developer Advocate"}]

tasks:
  - id: send_data
    type: io.kestra.plugin.fs.http.Request
    uri: https://reqres.in/api/users
    method: POST
    contentType: application/json
    body: "{{ inputs.payload }}"

  - id: print_status
    type: io.kestra.core.tasks.log.Log
    message: "{{ outputs.send_data.body }}"

Example 2

id: rest_api_with_inputs
namespace: dev

labels:
  env: prod
  country: US

tasks:
  - id: extract
    type: io.kestra.plugin.fs.http.Request
    uri: https://dummyjson.com/products
    method: GET

  - id: load
    type: io.kestra.plugin.fs.http.Request
    uri: https://reqres.in/api/products
    method: POST
    contentType: application/json
    body: "{{outputs.extract.body}}"
Skraye commented 5 months ago

HttpRequest works well, the issue is in the way you send the data : From your Kestra Flow, you're sending a list of object :

 defaults: |
      [{"name": "Will", "job": "Developer Advocate"}]

While you send only an object in Postman : image

Update your input to only send the object :

 defaults: |
      {"name": "Will", "job": "Developer Advocate"}

And you'll get the expected result : image