Azure DevOps Module Make an API Call

:bullseye: What is your goal?

Send an API call to Azure DevOps

:thinking: What is the problem & what have you tried?

the api call does not need a body, so I try to leave it empty, but when I run the scenario, I have the following error.

:clipboard: Error messages or input/output bundles

Body is not a valid JSON. Unexpected token ‘’, “{”$id":“1”… is not valid JSON

:camera_with_flash: Screenshots (scenario flow, module settings, errors)

Welcome to the Make community!

As you’ve not provided screenshots, I can only make a guess.

Modules Using Raw JSON

The HTTP “Make a request” or an app’s universal “Make an API call” modules uses raw JSON to transmit data. The HTTP body content field does not automatically escape variables mapped into it, and if the mapped variables contain JSON reserved characters (e.g. from the output of an AI module, or another JSON string), it breaks the structure of your outermost JSON.

Simple text string in the value is okay :white_check_mark:

Inserting special characters (like " and line-breaks), makes the JSON invalid. :cross_mark:

Correctly escaped special JSON characters in the value :white_check_mark:

Escaping Variables Before Mapping Into Another JSON (string)

Most of the time, you cannot directly map variables containing text content into another JSON string without escaping them, as the variable might contain special characters that are reserved. Special characters in JSON needs to be escaped (encoded) as a “literal” character, otherwise they make the whole JSON invalid when you map the variable value when creating another JSON string.

A. Using “Transform to JSON” Module

You can escape variables by passing the text into the “Transform to JSON” module. You can also build a valid JSON string by using a Data Structure with the “Create JSON” module. Then, you can map the output of the Transform module into another JSON, or simply use the whole output of the Create module.

:warning: Note:

When using the “Transform to JSON” module on a string-type variable, the output should already contain the double quotes " " around your text, so when you map this output into your JSON, do not wrap another pair of double quotes around it!

B. Using “Replace” Function

Alternatively, you can use the built-in function replace to replace several special characters with their escaped versions. To do this, simply paste this into the field, and replace the 1.text variable:

{{ replace(replace(1.text; "/([""\\])/g"; "\$1"); "/\r?\n\r?/g"; "\n") }}
:high_voltage: Make Input Markup: Copy-paste the above into the field, including start/end curly brackets for it to import as intended :warning:

Further Information

For more information on JSON and escaping special characters, see:

@samliew