Power Automate中SharePoint文件重命名HTTP请求步骤报错咨询
问题描述
在Power Automate的「向SharePoint发送HTTP请求」步骤中,尝试给文件重命名并追加Compose步骤结果时触发错误:
The expression "web/GetFileByServerRelativeUrl('/sites/ESMManila/Shared Documents/General/WorkloadPlanning/CurrentWorkPlan.xlsx')/moveto(newurl=concat('/sites/ESMManila/Shared Documents/General/WorkloadPlanning/',outputs('Compose'),'WorkPlan','.xlsx'))" is not valid.
使用的URI为:_api/web/GetFileByServerRelativeUrl('/sites/ESMManila/Shared%20Documents/General/WorkloadPlanning/CurrentWorkPlan.xlsx')/moveto(newurl=concat('/sites/ESMManila/Shared%20Documents/General/WorkloadPlanning/',outputs('Compose'),'WorkPlan','.xlsx'))
错误原因
你把Power Automate的concat()表达式直接嵌入到了SharePoint REST API的URI中,SharePoint REST API无法识别Power Automate的表达式语法,moveto方法的newurl参数需要传入已经拼接完成的完整字符串路径,而非表达式本身。
解决步骤
第一步:先拼接好完整的新文件路径
新增一个Compose步骤(或复用现有步骤扩展),在表达式框中写入拼接规则:concat('/sites/ESMManila/Shared Documents/General/WorkloadPlanning/', outputs('Compose'), 'WorkPlan', '.xlsx')若原Compose输出包含多余空格,可添加
trim()处理:concat(..., trim(outputs('Compose')), ...)第二步:修改HTTP请求的URI
将URI中的concat(...)替换为新Compose步骤的动态输出,确保传入的是解析后的完整路径:_api/web/GetFileByServerRelativeUrl('/sites/ESMManila/Shared%20Documents/General/WorkloadPlanning/CurrentWorkPlan.xlsx')/moveto(newurl='@{outputs('新Compose步骤名称')}')如果需要覆盖同名文件,可添加
flags=1参数(1表示强制覆盖,0为不覆盖):_api/web/GetFileByServerRelativeUrl('/sites/ESMManila/Shared%20Documents/General/WorkloadPlanning/CurrentWorkPlan.xlsx')/moveto(newurl='@{outputs('新Compose步骤名称')}', flags=1)第三步:确认请求配置
确保HTTP请求的方法为POST,请求头添加Accept: application/json;odata=verbose,避免返回格式异常。
内容的提问来源于stack exchange,提问作者Dren

