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

时间:2019-05-11 13:30:32

标签: graphql shopify

我正在尝试编写一些PHP代码以在shopify graphql api上运行一个变体。当我从命令行curl运行突变时,它运行良好。但是,由于某些原因,相同的PHP curl会返回错误/

这是命令行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}}}}

我无法从多个文件中发布确切的php代码,但这是php curl调用的有效负载

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

和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

    '
    )

返回的错误是:

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

1 个答案:

答案 0 :(得分:2)

最好能多看一些php代码以查看错误可能是什么,但问题可能与您没有在突变中转义引号有关。

尝试更改:

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

收件人:

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

要转义字符串中的引号