从 TypeScript Azure 函数调用 MS Power Automate
call MS Power Automate from a TypeScript Azure function
如何从 TypeScript Azure 函数触发 MS Power Automate HTTPtrigger。任何人?我一直在尝试这个,但没有任何运气。
const data = JSON.stringify({
todo: 'Buy the milk'
})
const options = {
hostname: flowUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.write(data)
req.end()
您似乎只是在 options
中使用了 hostname
属性,但没有使用 port
和 path
属性。我们不能把整个流程url放在options
的hostname
中,我们需要把它分开为hostname
、port
和path
。
例如我的流程url是https://prod-06.eastasia.logic.azure.com:443/workflows/e79330xxxxxxxxxxxcf029ac/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=mEAzy9xxxxxxxxxxxxxxxxxPqCwJBCc2mg
,那么代码应该是这样的:
const options = {
hostname: "prod-06.eastasia.logic.azure.com", //note: do not add "https://" here
method: 'POST',
port: '443',
path: '/workflows/e79330xxxxxxxxxxxcf029ac/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=mEAzy9xxxxxxxxxxxxxxxxxPqCwJBCc2mg',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
此更改后,代码可以在我的 power automate 中触发 http 触发器。
如何从 TypeScript Azure 函数触发 MS Power Automate HTTPtrigger。任何人?我一直在尝试这个,但没有任何运气。
const data = JSON.stringify({
todo: 'Buy the milk'
})
const options = {
hostname: flowUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.write(data)
req.end()
您似乎只是在 options
中使用了 hostname
属性,但没有使用 port
和 path
属性。我们不能把整个流程url放在options
的hostname
中,我们需要把它分开为hostname
、port
和path
。
例如我的流程url是https://prod-06.eastasia.logic.azure.com:443/workflows/e79330xxxxxxxxxxxcf029ac/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=mEAzy9xxxxxxxxxxxxxxxxxPqCwJBCc2mg
,那么代码应该是这样的:
const options = {
hostname: "prod-06.eastasia.logic.azure.com", //note: do not add "https://" here
method: 'POST',
port: '443',
path: '/workflows/e79330xxxxxxxxxxxcf029ac/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=mEAzy9xxxxxxxxxxxxxxxxxPqCwJBCc2mg',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
此更改后,代码可以在我的 power automate 中触发 http 触发器。