简体   繁体   English

Shopify GraphQL突变返回“ \\ gid \\”(IDENTIFIER)上的解析错误”

[英]Shopify GraphQL mutation returns “Parse error on \”gid\“ (IDENTIFIER)”

I am trying write some PHP code to run a mutation on the shopify graphql api. 我正在尝试编写一些PHP代码以在shopify graphql api上运行变异。 When I run the mutation from command line curl, it works well. 当我从命令行curl运行突变时,它运行良好。 But, for some reason PHP curl for the same returns an error/ 但是,由于某些原因,相同的PHP curl会返回错误/

Here is the command line curl and its output. 这是命令行curl及其输出。

    curl -X  POST \
    > "https://myshopname.myshopify.com/admin/api/2019-04/graphql.json" \
    > -H "Content-Type: application/graphql" \
    > -H "X-Shopify-Access-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
    > -d '
    > mutation{
    > productVariantUpdate(input: {
    >     id: "gid://shopify/ProductVariant/126493786xxxx",
    >     price: 2998.5
    >   }){
    >     productVariant{ id, price }
    >   }
    > 
    > }
    > '
    {"data":{"productVariantUpdate":{"productVariant":{"id":"gid:\/\/shopify\/ProductVariant\/126493786xxxx","price":"2998.50"}}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}

I cannot post the exact php code since its from multiple files, but here is the payload of the php curl call 由于它来自多个文件,因此我无法发布确切的php代码,但这是php curl调用的有效负载

    mutation{productVariantUpdate(input: {    id: "gid://shopify/ProductVariant/126493786xxxx",    price: 2998.5  }){    productVariant{ id, price }  }}

and the curl_info output 和curl_info输出

    array(
        'url' => 'https://myshopname.myshopify.com/admin/api/2019-04/graphql.json',
        'content_type' => 'application/json; charset=utf-8',
        'http_code' => (int) 200,
        'header_size' => (int) 2431,
        'request_size' => (int) 385,
        'filetime' => (int) -1,
        'ssl_verify_result' => (int) 0,
        'redirect_count' => (int) 0,
        'total_time' => (float) 0.719179,
        'namelookup_time' => (float) 0.060711,
        'connect_time' => (float) 0.123953,
        'pretransfer_time' => (float) 0.273472,
        'size_upload' => (float) 151,
        'size_download' => (float) 110,
        'speed_download' => (float) 152,
        'speed_upload' => (float) 210,
        'download_content_length' => (float) -1,
        'upload_content_length' => (float) 151,
        'starttransfer_time' => (float) 0.718514,
        'redirect_time' => (float) 0,
        'redirect_url' => '',
        'primary_ip' => '23.227.63.64',
        'certinfo' => array(),
        'primary_port' => (int) 443,
        'local_ip' => '192.168.0.101',
        'local_port' => (int) 40882,
        'request_header' => 'POST /admin/api/2019-04/graphql.json HTTP/1.1
    Host: alberto-torresi-2.myshopify.com
    User-Agent: wcurl
    Accept: */*
    Content-Type: application/graphql
    X-Shopify-Access-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Content-Length: 151

    '
    )

The error returned is: 返回的错误是:

    {"errors":[{"message":"Parse error on \"gid\" (IDENTIFIER) at [1, 49]","locations":[{"line":1,"column":49}]}]}

It would be good to see a bit more of the php code to see what the error might be, but the issue could be related to you not escaping the quotes in the mutation. 最好能多看一些php代码,以查看错误可能是什么,但问题可能与您没有在突变中转义引号有关。

Try changing: 尝试更改:

mutation{productVariantUpdate(input: {    id: "gid://shopify/ProductVariant/126493786xxxx",    price: 2998.5  }){    productVariant{ id, price }  }}

to: 至:

mutation{productVariantUpdate(input: {    id: \"gid://shopify/ProductVariant/126493786xxxx\",    price: 2998.5  }){    productVariant{ id, price }  }}

To escape the quotes in the string 转义字符串中的引号

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

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