Hi Jimmy,
I just tested this with the following map configuration
- map:
title: map
description: ''
inputs: {}
outputs:
output:
schema:
type: object
properties:
hello:
type: string
name: hello
foo:
type: string
name: foo
variable: message.body
content: text/plain
actions:
- set: output.hello
default: world
- set: output.foo
default: bar
version: 2.1.0
options:
mapEmulateV4EmptyJSONObject: false
mapEmulateV4DefaultRequiredProps: false
mapEnablePostProcessingJSON: false
mapReferenceLimit: 1
The map policy will produce what it is asked to do, a JSON object that matches the inline output schema, specifically {"hello":"world","foo":"bar"}
, but as expected the response content-type header is as configured in the map policy of text/plain
since the output variable is message.body
so message.headers.content-type
will be set to the specified content-type value. Perhaps I'm not fully understanding your issue?
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Thu January 04, 2024 03:02 PM
From: Steve Linn
Subject: How can I transform a JSON response from an API to plain text?
Hi Jimmy,
You're saying your map policy is configured with an output for message.body
that configures the output to have a content-type of text/plain
but still has an inline schema that defines a JSON structure? I believe the mapping will still create a JSON object for message.body
but the message.headers.content-type should be text/plain
although quite frankly I've never tested that use case, something I'll test out for sure. Assuming the output from the map policy places a JSON object into message.body, the serialization of that object, either sent to some target-url in an invoke policy or returned to the client as the result of the API, should still return a serialized string. Are you saying that the map policy is generating an application/json
content type response header in this use case?
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Fri December 15, 2023 04:47 PM
From: JIMMY VIVAS PERILLA
Subject: How can I transform a JSON response from an API to plain text?
I currently have an api that in its response has a map node with the following configuration:![](https://dw1.s81c.com//IMWUC/MessageImages/83b3c1524bff4530a3c3c8dd0da81dcf.png)
and in the swagger it has the following property:
![](https://dw1.s81c.com//IMWUC/MessageImages/aa7a849e2efc477abec7c6a9573d758f.png)
However, the response I get when testing the API by postman always arrives in JSON format, the client is requesting that the response obtained be plain text.
Can this be done? Can you help me with the code and execution?
Thank you
------------------------------
JIMMY VIVAS PERILLA
------------------------------