在Azure Logic App中解析动态属性名称

时间:2016-05-04 23:46:18

标签: json azure azure-logic-apps

我一直在玩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)。这里的问题是列表中的对象&#34; 586327616&#34;是动态的,每篇文章都有变化,我似乎无法将其解析为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"
    }

对于表达式,我尝试将响应转换为字符串,使用coalesce并尝试使用索引进行访问,但似乎没有任何效果。在错误中,它告诉我可用属性是什么,例如:

{"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.'."}

我觉得在不知道属性名称的情况下构建表达式是不可能的,有没有人做过类似的事情?

0 个答案:

没有答案