Skip to content

APITool always assumes JSON response, fails with other content types (CSV, plain text, XML) #135

@loukratz-bv

Description

@loukratz-bv

Description:

The APITool executor currently hardcodes JSON response parsing in execute_api_tool:

# qtype/interpreter/executors/invoke_tool_executor.py, line ~199
result = response.json()

This causes failures when APIs return non-JSON content types like CSV, plain text, or XML, even when the appropriate Accept header is set.

Example:
An API endpoint returns CSV data with Accept: text/csv header:

- id: get_csv_data
  type: APITool
  endpoint: "https://api.example.com/export"
  method: GET
  headers:
    accept: text/csv

Error:

error: API request failed: Expecting value: line 1 column 1 (char 0)

Proposed Solution:

  1. Add an optional response_type field to APITool (default: json)
  2. Support json, text, binary, and auto (based on Content-Type header)
  3. Parse response accordingly:
    • json: response.json()
    • text: response.text
    • binary: response.content
    • auto: detect from Content-Type header

Workaround:
Use a Python function tool with requests library for full control over response handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions