Store HTTP request json body as a string (#12931)

Variables can be used without surrounding quotes.

The formatting is also preserved for raw json.

We would have to do additional work if we want to add other types of
bodies, like form data.

## Demo


https://github.com/user-attachments/assets/498dd9c8-6654-4440-9ab0-35bad5e34ca8

Closes https://github.com/twentyhq/core-team-issues/issues/1129

Related to https://github.com/twentyhq/core-team-issues/issues/1117.
Doesn't solve the issue for webhooks but does for http body input.
This commit is contained in:
Baptiste Devessier
2025-06-30 15:34:21 +02:00
committed by GitHub
parent 8272e5dfd0
commit d4fe8efd7f
12 changed files with 304 additions and 41 deletions

View File

@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
import { isString } from '@sniptt/guards';
import axios, { AxiosRequestConfig } from 'axios';
import { WorkflowExecutor } from 'src/modules/workflow/workflow-executor/interfaces/workflow-executor.interface';
@ -52,7 +53,9 @@ export class HttpRequestWorkflowAction implements WorkflowExecutor {
};
if (['POST', 'PUT', 'PATCH'].includes(method) && body) {
axiosConfig.data = body;
const parsedBody = isString(body) ? JSON.parse(body) : body;
axiosConfig.data = parsedBody;
}
const response = await axios(axiosConfig);

View File

@ -2,13 +2,15 @@ export type WorkflowHttpRequestActionInput = {
url: string;
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
headers?: Record<string, string>;
body?: Record<
string,
| string
| number
| boolean
| null
| undefined
| Array<string | number | boolean | null>
>;
body?:
| Record<
string,
| string
| number
| boolean
| null
| undefined
| Array<string | number | boolean | null>
>
| string;
};