PHP Shopify 图形 API。错误语法错误,[33, 2] 处出现意外的无效标记 ("\"")

问题描述 投票:0回答:1

我使用 cURL,而不是 github 库。 我有下一个代码

$query = <<<GRAPHQL
        mutation InventorySet(\$input: [InventorySetQuantitiesInput!]!)
        { 
            inventorySetQuantities(input: \$input) {
                inventoryAdjustmentGroup {
                    createdAt
                    reason
                    changes {
                        name
                        delta
                    }
                }
                userErrors {
                    field
                    message
                }
            }
       }";
       GRAPHQL;

        $variables = [
          'input' => [
              'name' => 'available',
              'quantities' => [
                'inventoryItemId' => $inventoryItemId,
                  'locationId' => $locationId,
                  'quantity' => $newQuantity
              ],
              'reason' => 'correction'
          ]
        ];
        return $this->makeGraphQLRequest($query, $variables);

为什么我会收到错误消息

syntax error, unexpected invalid token ("\"") at [33, 2]

请帮忙

代码中的错误说明和修复内容

php graphql shopify-api
1个回答
0
投票

请用此替换您的查询,并且在变量中您需要添加一个键“compareQuantity”,其值将是现有产品的可用数量,例如:0、1、2 等。

        mutation InventorySet($input: InventorySetQuantitiesInput!) {
          inventorySetQuantities(input: $input) {
            inventoryAdjustmentGroup {
              createdAt
              reason      
              changes {
                name
                delta
              }
            }
            userErrors {
              field
              message
            }
          }
        }

$variables = [
          'input' => [
              'name' => 'available',
              'quantities' => [
                'inventoryItemId' => $inventoryItemId,
                  'locationId' => $locationId,
                  'quantity' => $newQuantity,
                  'compareQuantity'=> 1
              ],
              'reason' => 'correction'
          ]
        ];
© www.soinside.com 2019 - 2024. All rights reserved.