You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GCP Workflow调用API后无法将JSON响应写入GCS存储桶求助

故障原因

配置存在多处语法、逻辑错误,导致GCS写入步骤完全无法执行,具体问题如下:

  • 拼写与YAML语法错误
    • swicth为拼写错误,正确关键字为switch
    • 条件满足后跳转目标写为readwikipedia,和实际定义的步骤名readWiki不匹配,会触发步骤找不到的运行错误
    • Wiki API调用的查询参数search:${searchTerm}冒号后缺失必填空格,不符合YAML语法规范
    • GCS写入步骤load_gcs后缺失冒号,步骤定义无效
    • 输入校验逻辑中判断存在的键为全小写searchterm,实际取值用的是驼峰input.searchTerm,键名不匹配会导致入参取值失败
  • 逻辑顺序错误
    • 原returoOutput步骤直接执行return操作,工作流遇到return会立即终止,后面的GCS写入步骤永远不会被执行
  • GCS接口调用参数错误
    • 调用GCS对象上传接口时未指定内容类型,直接传入数组结构的响应内容会被接口识别为非法请求
  • 权限前置要求
    • 工作流绑定的运行服务账号需要提前在目标存储桶test_buck上绑定存储对象创建者角色,否则会触发403权限拒绝错误
修正后完整配置
main:
    params: [input]
    steps:
    - checkInput:
        switch:
            - condition: ${"searchTerm" in input}
              assign:
                - searchTerm: ${input.searchTerm}
              next: readWiki
    - getcurrenttime:
        call: http.get
        args:
            url: https://us-central-workflowsample.cloudfunctions.net/datetime
        result: currentDate
    - setFromcallResult:
        assign:
            - searchTerm: ${currentDate.body.dayOfTheWeek}
    - readWiki:
        call: http.get
        args:
            url: https://en.wikipedia.org/w/api.php
            query:
                action: opensearch
                search: ${searchTerm}
        result: wikiResult
    - load_gcs:
        call: googleapis.storage.v1.objects.insert
        args:
            bucket: "test_buck"
            uploadType: "media"
            name: "sample.json"
            body:
                contentType: "application/json"
                data: ${json.encode(wikiResult.body[1])}
    - returnOutput:
        return: ${wikiResult.body[1]}
关键修正点说明
  • 修正所有拼写、YAML格式错误,统一步骤名、入参键名的大小写匹配规则
  • 调整步骤执行顺序:先完成GCS文件写入,最后执行返回操作,保证写入逻辑能被正常触发
  • 调用GCS上传接口时明确指定内容类型为application/json,通过json.encode把数组结构的返回值转成合法JSON字符串作为上传内容
  • 修正跳转目标的名称匹配问题,确保传入搜索词时能正确跳到Wiki查询步骤

内容的提问来源于stack exchange,提问作者Prithwiraj Samanta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 19:57:14