我一直在玩 Azure Logic Apps 并尝试检索 Pocket (ReadItLater) 文章,以便我可以在我喜欢的任务管理器中创建一个新任务。我有两个 HTTP 连接器(一个用于使用 Pocket API 进行检索操作,另一个用于将数据发布到 Todoist(我首选的任务管理器)。
我可以检索文章并且响应看起来像(删除了下面的一些属性以便于阅读):
{
"statusCode": 200,
"headers": {
"pragma": "no-cache",
"status": "200 OK"
},
"body": {
"status": 1,
"complete": 1,
"list": {
"586327616": {
"item_id": "586327616",
"resolved_id": "586327616",
"given_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"given_title": "slick - the last carousel you'll ever need",
"time_added": "1396652224",
"time_updated": "1405156517",
"resolved_title": "slick",
"resolved_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"excerpt": "Add slick.js before your closing <body> tag, after jQuery (requires jQuery 1.7 +) <script type=\"text/javascript\" src=\"slick/slick.min.",
"word_count": "22"
}
}
}
}
现在我想解析上述响应以检索单个文章属性(即resolved_title)。这里的问题是“586327616”列表下的对象是动态的,并且每篇文章都会发生变化,我似乎无法将其解析为 Logic App 中的表达式。我当前在 Logic App 中的操作如下所示:
"postToTodoist": {
"conditions": [
{
"expression": "@equals(outputs('getPocketArticles')['statusCode'], 200)"
},
{
"dependsOn": "getPocketArticles"
}
],
"inputs": {
"body": "@{outputs('getPocketArticles')['body']['list'][0]['resolved_title']}",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"method": "POST",
"repeat": {},
"uri": "https://todoist.com/API/v6/add_item"
},
"type": "Http"
}
对于表达式,我尝试将响应转换为字符串,使用合并并尝试使用索引进行访问,但似乎没有任何效果。在错误中,它告诉我可用属性是什么,即:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'postToTodoist' inputs at line '1' and column '11': 'The template language expression 'coalesce(body('getPocketArticles')['list']).resolved_title' cannot be evaluated because property 'resolved_title' doesn't exist, available properties are '586327616'. Please see https://aka.ms/logicexpressions for usage details.'."}
我觉得在不知道属性名称的情况下无法构造表达式,有没有人做过类似的事情?