如何在Logic Apps中获取HTTP响应的access_token值
如何正确获取HTTP响应中的access_token值?
我需要从HTTP响应中提取access_token值,该响应的结构如下:
"body": { "token_type": "string", "expires_in": "number but as string", "ext_expires_in": "same", "expires_on": "same", "not_before": "number but as string", "resource": "string", "access_token": "string" }
我在「设置变量」操作中使用了表达式 body('parse_JSON')?[variables('access_token')],结果触发了以下错误:
InvalidTemplate. Unable to process template language expressions in action 'Set_Access_Token' inputs at line '0' and column '0': 'The template language expression 'body('Parse_JSON')?[triggerBody()?['access_token']]' cannot be evaluated because property '' cannot be selected. 请查看逻辑表达式相关文档了解详情.'
我的工作流结构如下:
正确的提取方式
- 若已通过「Parse JSON」操作完成响应解析,直接通过以下两种方式访问
access_token属性即可:- 方括号写法:
body('Parse_JSON')?['access_token'] - 点符号写法:
body('Parse_JSON')?.access_token
- 方括号写法:
- 你之前的错误原因是误用了
variables('access_token'),如果该变量未定义或值为空,会导致尝试访问空属性名,进而触发错误。直接使用字符串字面量'access_token'或点符号访问目标属性即可解决问题。
内容的提问来源于stack exchange,提问作者Mostafa Bouzari
相关产品推荐
相关产品推荐

