MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / getWebhookCode

Function getWebhookCode

packages/ui/src/views/chatflows/APICodeDialog.jsx:308–352  ·  view source on GitHub ↗
(codeLang, apiKey)

Source from the content-addressed store, hash-verified

306 }
307
308 const getWebhookCode = (codeLang, apiKey) => {
309 const url = `${baseURL}/api/v1/webhook/${dialogProps.chatflowid}`
310 const sendsBody = webhookMethod !== 'GET' && webhookMethod !== 'DELETE'
311 const isJson = webhookContentType === 'application/json'
312 const sampleBodyJs = isJson ? '{ example: "value" }' : '"example=value"'
313 const sampleBodyPy = isJson ? '{"example": "value"}' : '"example=value"'
314 const sampleBodyCurl = isJson ? '{"example": "value"}' : 'example=value'
315
316 if (codeLang === 'Python') {
317 const headers = [`"Content-Type": "${webhookContentType}"`]
318 if (apiKey) headers.push(`"Authorization": "Bearer ${apiKey}"`)
319 if (webhookEnableAuth) headers.push(`"${webhookSignatureHeader}": "<signature>"`)
320 const bodyArg = sendsBody ? (isJson ? `, json=${sampleBodyPy}` : `, data=${sampleBodyPy}`) : ''
321 return `import requests
322
323API_URL = "${url}"
324headers = {${headers.join(', ')}}
325
326response = requests.${webhookMethod.toLowerCase()}(API_URL, headers=headers${bodyArg})
327print(response.json())
328`
329 } else if (codeLang === 'JavaScript') {
330 const headers = [`"Content-Type": "${webhookContentType}"`]
331 if (apiKey) headers.push(`Authorization: "Bearer ${apiKey}"`)
332 if (webhookEnableAuth) headers.push(`"${webhookSignatureHeader}": "<signature>"`)
333 const bodyLine = sendsBody ? `,\n body: ${isJson ? `JSON.stringify(${sampleBodyJs})` : sampleBodyJs}` : ''
334 return `const response = await fetch(
335 "${url}",
336 {
337 method: "${webhookMethod}",
338 headers: { ${headers.join(', ')} }${bodyLine}
339 }
340);
341const result = await response.json();
342console.log(result);
343`
344 } else if (codeLang === 'cURL') {
345 const parts = [`curl ${url}`, `-X ${webhookMethod}`, `-H "Content-Type: ${webhookContentType}"`]
346 if (apiKey) parts.push(`-H "Authorization: Bearer ${apiKey}"`)
347 if (webhookEnableAuth) parts.push(`-H "${webhookSignatureHeader}: <signature>"`)
348 if (sendsBody) parts.push(`-d '${sampleBodyCurl}'`)
349 return parts.join(' \\\n ')
350 }
351 return ''
352 }
353
354 const getCode = (codeLang) => {
355 if (isWebhookFlow) return getWebhookCode(codeLang, null)

Callers 2

getCodeFunction · 0.85
getCodeWithAuthorizationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected