Fix cURL on Api Modal (#1524)
📝 (utils.ts): add support for retrieving output IDs from flow data to include in the curl code 📝 (utils.ts): update getCurlCode function to include the arrayOfOutputs in the curl code
This commit is contained in:
commit
9c59f0a94a
1 changed files with 25 additions and 2 deletions
|
|
@ -381,16 +381,39 @@ export function getCurlCode(
|
|||
const tweaks = buildTweaks(flow);
|
||||
const inputs = buildInputs();
|
||||
|
||||
const arrayOfOutputs = getOutputIds(flow);
|
||||
|
||||
return `curl -X POST \\
|
||||
${window.location.protocol}//${window.location.host}/api/v1/run/${flowId} \\
|
||||
-H 'Content-Type: application/json'\\${
|
||||
!isAuth ? `\n -H 'x-api-key: <your api key>'\\` : ""
|
||||
}
|
||||
-d '{"inputs": [${inputs}], "tweaks": ${
|
||||
-d '{"inputs": [${inputs}],
|
||||
"outputs": [${arrayOfOutputs}],
|
||||
"stream": false,
|
||||
"tweaks": ${
|
||||
tweak && tweak.length > 0
|
||||
? buildTweakObject(tweak)
|
||||
: JSON.stringify(tweaks, null, 2)
|
||||
}}'`;
|
||||
}}'
|
||||
`;
|
||||
}
|
||||
|
||||
export function getOutputIds(flow) {
|
||||
const nodes = flow.data!.nodes;
|
||||
|
||||
const arrayOfOutputs = nodes.reduce((acc: string[], node) => {
|
||||
if (node.data.type.toLowerCase().includes("output")) {
|
||||
acc.push(node.id);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const arrayOfOutputsJoin = arrayOfOutputs
|
||||
.map((output) => `"${output}"`)
|
||||
.join(", ");
|
||||
|
||||
return arrayOfOutputsJoin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue