shopify-api-node lib giving Error: Updating a variant

Shopify Partner
14 1 0

As per documentation here.

I am executing the following code:

await shopify.productVariant
        .update({
            "variant":
            {
                "id": variantId,
                "metafields": [
                    {
                        "key": theKey,
                        "value": 1,
                        "value_type": "integer",
                        "namespace": theNamespace
                    }
                ]
            }
        })

And am receiving the following error:

ERROR:
{
  name: "RequestError",
  host: undefined,
  hostname: "case-size-selector-development-store.myshopify.com",
  method: "PUT",
  path: "/admin/variants/[object Object].json",
  protocol: "https:",
  url: undefined
}
0 Likes
Highlighted
Shopify Partner
14 1 0

Also tried using JSON.stringify on the request object but that also failed.

await shopify.productVariant
        .update(
            JSON.stringify({
                "variant":
                {
                    "id": variantId,
                    "metafields": [
                        {
                            "key": theKey,
                            "value": 1,
                            "value_type": "integer",
                            "namespace": theNamespace
                        }
                    ]
                }
            })
        )

Error:

ERROR:
{
  name: "HTTPError",
  host: undefined,
  hostname: "case-size-selector-development-store.myshopify.com",
  method: "PUT",
  path: "/admin/variants/{\"variant\":{\"id\":16207020490786,\"metafields\":[{\"key\":\"'Wholesale'\",\"value\":1,\"value_type\":\"integer\",\"namespace\":\"'case_size'\"}]}}.json",
  protocol: "https:",
  url: undefined,
  statusCode: 400,
  statusMessage: "Bad Request",
  headers: {
    server: "nginx",
    date: "Thu, 11 Apr 2019 21:33:15 GMT",
    "content-type": "application/json; charset=utf-8",
    "transfer-encoding": "chunked",
    connection: "close",
    "x-sorting-hat-podid": "33",
    "x-sorting-hat-shopid": "4983586850",
    "referrer-policy": "origin-when-cross-origin",
    "x-frame-options": "DENY",
    "x-shopid": "4983586850",
    "x-shardid": "33",
    "x-stats-userid": "26989658146",
    "x-stats-apiclientid": "2785525",
    "x-stats-apipermissionid": "86388211746",
    http_x_shopify_shop_api_call_limit: "1/40",
    "x-shopify-shop-api-call-limit": "1/40",
    "x-shopify-api-version": "2019-04",
    "strict-transport-security": "max-age=7889238",
    "x-request-id": "6f0333a5-5020-43c4-8928-7277c7fdbcc8",
    "x-shopify-stage": "production",
    "content-security-policy": "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=update&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_variants&source%5Bsection%5D=admin_api&source%5Buuid%5D=6f0333a5-5020-43c4-8928-7277c7fdbcc8",
    "x-content-type-options": "nosniff",
    "x-download-options": "noopen",
    "x-permitted-cross-domain-policies": "none",
    "x-xss-protection": "1; mode=block; report=/xss-report?source%5Baction%5D=update&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_variants&source%5Bsection%5D=admin_api&source%5Buuid%5D=6f0333a5-5020-43c4-8928-7277c7fdbcc8",
    "x-dc": "chi2,gcp-us-central1"
  }
}
0 Likes