简体   繁体   English

PowerShell GraphQL 突变解析错误

[英]PowerShell GraphQL Mutation Parsing Error

I'm querying the Monday API v2 ( https://monday.com/developers/v2 ) I'm getting stuck in getting the PowerShell query to work, the script is below:我正在查询星期一 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 

And it keeps returning它不断返回

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

The mutation query in Postman works fine Postman 中的突变查询工作正常

change_column_value (board_id: 528033866, item_id: 574335355, column_id: "status_1", value: "{\"index\": 1}"){id}
}

I have tried working with what quotes are escaped, but I still haven't been able to get it to run succesfully.我尝试过处理转义的引号,但我仍然无法让它成功运行。 I was referencing the tips here https://www.reddit.com/r/PowerShell/comments/b9jasa/query_graphql_with_powershell/我在这里参考了提示https://www.reddit.com/r/PowerShell/comments/b9jasa/query_graphql_with_powershell/

Any thoughts on how to fix this error?关于如何解决此错误的任何想法?

EDIT: Sorry forgot to add the current query (not mutation) that works fine through Powershell编辑:抱歉忘记添加通过 Powershell 可以正常工作的当前查询(不是突变)

$bodytxt = '{"query":"{  boards (ids: 528033866) {    groups (ids: \"group_title\"){        items () {            id            name       updates () {  body }     column_values () {        id        title        value    text  }        }        title    }    }  }"}'

The easiest way to create a GraphQL query is创建 GraphQL 查询的最简单方法是

  1. create a hashtable with HERE-STRINGS使用HERE-STRINGS创建一个哈希表
  2. convert it to a JSON string with ConvertTo-Json .使用ConvertTo-Json将其转换为 JSON 字符串。
$bodytxt = @{"query" = @'
  mutation {
    change_column_value(
      board_id: 123123
      item_id: 456456
      column_id: "status1"
      value: "{\"index\":1}"
    ) {
      id
    }
  }
'@
} | ConvertTo-Json

White spaces inside @'...'@ are optional. @'...'@中的空格是可选的。


reply to this comment回复此评论

it should always work in the API call with the GraphQL?它应该始终在使用 GraphQL 的 API 调用中工作?

I think it depends on services, but in most cases, yes.我认为这取决于服务,但在大多数情况下,是的。 application/json is the GraphQL default content type for the request body. application/json是请求正文的 GraphQL 默认内容类型。

and for monday.com星期一。com

Be sure to use the application/json content type请务必使用 application/json 内容类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM