gpt4 book ai didi

powershell - PowerShell GraphQL突变解析错误

转载 作者:行者123 更新时间:2023-12-03 00:05:58 24 4
gpt4 key购买 nike

我正在查询Monday API v2(https://monday.com/developers/v2),我无法使PowerShell查询正常工作,脚本如下:

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
$url = "https://api.monday.com/v2/"
$hdr = @{ }
$hdr.Add("Authorization", "redacted")
$hdr.Add("Content-Type", "application/json")

$bodytxt = '{"query":"mutation{change_column_value (board_id: 528033866, item_id: 574335355, column_id: \"status_1\", value: "{\"index\": 1}") {id}}"}'
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt
Write-Host $response

而且不断返回
{"errors":[{"message":"Parse error on \": 1}\" (STRING) at [1, 110]","locations":[{"line":1,"column":110}]}],"account_id":5305133}

Postman中的突变查询工作正常
change_column_value (board_id: 528033866, item_id: 574335355, column_id: "status_1", value: "{\"index\": 1}"){id}
}

我曾尝试处理哪些转义的引号,但是我仍然无法使其成功运行。我在这里引用技巧 https://www.reddit.com/r/PowerShell/comments/b9jasa/query_graphql_with_powershell/

关于如何解决此错误的任何想法?

编辑:对不起忘了添加通过Powershell正常工作的当前查询(不是突变)
$bodytxt = '{"query":"{  boards (ids: 528033866) {    groups (ids: \"group_title\"){        items () {            id            name       updates () {  body }     column_values () {        id        title        value    text  }        }        title    }    }  }"}'

最佳答案

创建GraphQL查询的最简单方法是

  • HERE-STRINGS创建一个哈希表
  • 使用ConvertTo-Json将其转换为JSON字符串。

  • $bodytxt = @{"query" = @'
    mutation {
    change_column_value(
    board_id: 123123
    item_id: 456456
    column_id: "status1"
    value: "{\"index\":1}"
    ) {
    id
    }
    }
    '@
    } | ConvertTo-Json
    @'...'@内的空格是可选的。

    回复 this comment

    it should always work in the API call with the GraphQL?



    我认为这取决于服务,但是在大多数情况下,是的。 application/json是请求正文的GraphQL默认内容类型。

    monday.com

    Be sure to use the application/json content type

    关于powershell - PowerShell GraphQL突变解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61960272/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com