Type
Required: no
Default: automatic
(based on Content-Type
header)
Values: automatic
, json
, urlencoded
, text
(or string
), binary
, and xml
.
This directive specifies how to parse the data received from the server.
When automatic
is used for the response type, Make tries to parse the response based on its Content-Type
header.
Currently, Make recognizes only text/plain
, application/json
, application/x-www-form-urlencoded
and application/xml
(or text/xml
).
When specifying other types, Make ignores the Content-Type
header and tries to parse the response in the format that you have specified.
{
"response": {
"type": "json"
}
}
Custom response types based on status code
You can specify the type as a special object where keys are status codes, wildcard, or status code ranges. This may be necessary because some services return different responses with different status codes: JSON on success and TEXT on error, for example.
Type object specification
The
*
(wildcard) represents all responses and should always be present.The
[number]-[number]
represents a status code range.The
[number]
represents a status code.
When specifying ranges and multiple ranges include the same status code, the smallest range is selected. The *
has the largest range (1-999) and a number has the smallest range, for example, 455
is 455-455
range.
Ranges are counted inclusive from both sides, so if you specify a range 401-402
, both the 401
and 402
status codes will be processed by this range.
{
"response": {
"type": {
"*": "json", // parse all responses as JSON
"400-408": "text", // parse all 400-408 responses as text, overrides "*",
"406": "xml" // parse the 406 response as XML, overrides above definitions
}
}
}
XML type
It is not possible to convert XML to JSON objects one-to-one. However, in Make, there are methods to accessing nodes and attributes to parsed XML.
Everything is an array
Each parsed node is an array, even the root node. Even if in XML a node is single, it will still be represented in Make as an array.
<data>
<text>Hello, world</text>
</data>
Is parsed in Make as:
{
"data": {
"text": ["Hello, world"]
}
}
To access the value of <text>
node in the output, for example:
{
"response": {
"output": "body.data[].text[]"
}
}
Access the value of a node with attributes
If there are attributes present on the node you want to get the value of, you need to use _value
.
<data>
<text foo="bar">Hello, world</text>
</data>
Here, the previous example will not work, because the <text>
node has attributes.
Use this to access the value of the <text>
node:
{
"response": {
"output": "body.data[].text[]._value"
}
}
Access node attributes
In a similar manner, you can access node attributes with _attributes
:
<data>
<text foo="bar">Hello, world</text>
</data>
_attributes
is a collection where you can access each attribute’s value by its name:
{
"response": {
"output": "body.data[].text[]._attributes.foo"
}
}
Access nested nodes
When accessing nested XML nodes, access them via the array notation. When accessing nested elements, it doesn’t matter if the parent has attributes or not:
<data>
<items length="2">
<item>
<name>Foo</name>
</item>
<item>
<name>Bar</name>
</item>
</items>
</data>
To process these two items in the iterate
directive:
{
"response": {
"iterate": "body.data[].items[].item",
"output": {
"name": "{{item.name[]}}"
}
}
}
Rounded long ID numbers
In some cases, services might send JSON or XML with long IDs:
{
"id": 5189203162509781230504938,
"name": "blabla",
...
}
Since Make uses JavaScript, numbers exceeding the MAX_SAFE_INTEGER value may be rounded.
In this case, use type: text
to handle the response. Then, use the replace
(with RegEx) and parseJSON
functions to convert these long numbers to strings.
"response": {
"type": "text",
"output": "{{fixLongNumbers(body)}}"
}
This is not a problem when the third party sends an ID as a string
.
{
"id": "5189203162509781230504938",
"name": "blabla",
...
}
Last updated