SHOPIFY api change causes different test script errors

We created a simple project to set metafields in Shopify. We have 10-30 fields to set from a csv file. It stopped working after 2019-07 API. I do get a 201 response for the first field, then I get an error:
An error occurred while running test scripts for this request. Check Postman Console for more info.

The test is: pm.test(“Status test”, function () {
pm.response.to.have.status(201);
});
I should add that fist value does POST and I do get 201 created. But errors on the response data, which I do not need.

But the error will change from:’ JSONError: Unexpected token u in JSON at position 0
OR if I use API 2020-07 to JSONError: No data, empty input at 1:1

The response data is the same:
{“metafield”:{“id”:18765537247283,“namespace”:“specifications”,“key”:“height”,“value”:“20”,“value_type”:“string”,“description”:null,“owner_id”:4340467957811,“created_at”:“2021-02-25T11:23:15-05:00”,“updated_at”:“2021-02-25T11:23:15-05:00”,“owner_resource”:“product”,“admin_graphql_api_id”:“gid://shopify/Metafield/18765537247283”}}
for both.

I should also add I can see a message in the Runner for a split second: The request does not have any tests.

This always worked, please help.
TX,
ER

Hi @erspada,
Welcome to the community :wave:

Could you please provide some more details about what exactly is happening on your end?

Are you still getting the same responses as before? And all the requests are being sent without any errors?

Regarding the error:

JSONError: Unexpected token u in JSON at position 0

Are you attempting to parse your response to JSON? If yes, can you please show us how you do it?

A screenshot of the test and the response would be great, but since this is a public forum, please upload the screenshot only if it doesn’t contain any sensitive information or if you have blurred out the sensitive data.

If I have to take a wild guess based on the errors you are seeing, it appears that you might be facing issues with accessing your response as JSON.

OK, so we have variables in Shopify. We are uploaded a CSV with the values in the Runner:

The product_id and the first value ‘height’ in the csv does POST with 201, and appears correctly, but it fails, even if I select only 1 value.

My environment is this:


The test in the header folder is:

CSV:

Runner:

Here is the response body, which I do not need, the test us 201.

Error:

Thanks for your help.
ER

Here is the entire response:
product id that will be set: 4340467957811

:arrow_forward:POST https://xxxxxxxxxxxx.myshopify.com/admin/api/2021-01/products/4340467957811/metafields.json201735 ms

  • :arrow_forward:Network

:arrow_forward:Request Headers

Content-Type: application/json

User-Agent: PostmanRuntime/7.26.10

Accept: /

Cache-Control: no-cache

Postman-Token: a2b2e7ef-a5b5-4deb-8302-1ab2c877f838

Host: chriscoffee-dev.myshopify.com

Accept-Encoding: gzip, deflate, br

Connection: keep-alive

Cookie: _shopify_fs=2021-02-25T16%3A23%3A15Z; _shopify_y=d698f64c-bd9e-4fd9-b492-be2a4e0f2b58; _y=d698f64c-bd9e-4fd9-b492-be2a4e0f2b58

:arrow_forward:Request Body

{ “metafield”: { “namespace”: “specifications”, “key”: “width”, “value”: “31”, “value_type”: “string” } }

:arrow_forward:Response Headers

Date: Sun, 28 Feb 2021 15:03:08 GMT

Content-Type: application/json; charset=utf-8

Transfer-Encoding: chunked

Connection: keep-alive

X-Sorting-Hat-PodId: 50

X-Sorting-Hat-ShopId: 25163989043

Referrer-Policy: origin-when-cross-origin

X-Frame-Options: DENY

X-ShopId: 25163989043

X-ShardId: 50

X-Stats-UserId:

X-Stats-ApiClientId: 4639529

X-Stats-ApiPermissionId: 210925060147

X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at Shopify API License and Terms of Use

HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/80

X-Shopify-Shop-Api-Call-Limit: 1/80

X-Shopify-API-Version: 2021-01

Location: https://chriscoffee-dev.myshopify.com/admin/metafields/18765947895859

Strict-Transport-Security: max-age=7889238

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://cdn.shopifycdn.net https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.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=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fmetafields&source%5Bsection%5D=admin_api&source%5Buuid%5D=5dbf52ab-d197-4ede-8801-a0f5104df301

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=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fmetafields&source%5Bsection%5D=admin_api&source%5Buuid%5D=5dbf52ab-d197-4ede-8801-a0f5104df301

X-Dc: gcp-us-east1,gcp-us-central1,gcp-us-central1

NEL: {“report_to”:“network-errors”,“max_age”:2592000,“success_fraction”:0.0001}

NEL: {“report_to”:“network-errors”,“max_age”:2592000,“success_fraction”:0.0001}

Report-To: {“group”:“network-errors”,“max_age”:2592000,“endpoints”:[{“url”:“https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify”}]}

Report-To: {“group”:“network-errors”,“max_age”:2592000,“endpoints”:[{“url”:“https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify”}]}

X-Request-ID: 5dbf52ab-d197-4ede-8801-a0f5104df301

Set-Cookie: _y=d698f64c-bd9e-4fd9-b492-be2a4e0f2b58; Expires=Mon, 28-Feb-22 15:03:08 GMT; Domain=chriscoffee-dev.myshopify.com; Path=/; SameSite=Lax

Set-Cookie: _s=d087ea35-2a9b-45ca-a5bc-a91a8707743c; Expires=Sun, 28-Feb-21 15:33:08 GMT; Domain=chriscoffee-dev.myshopify.com; Path=/; SameSite=Lax

Set-Cookie: _shopify_y=d698f64c-bd9e-4fd9-b492-be2a4e0f2b58; Expires=Mon, 28-Feb-22 15:03:08 GMT; Domain=chriscoffee-dev.myshopify.com; Path=/; SameSite=Lax

Set-Cookie: _shopify_s=d087ea35-2a9b-45ca-a5bc-a91a8707743c; Expires=Sun, 28-Feb-21 15:33:08 GMT; Domain=chriscoffee-dev.myshopify.com; Path=/; SameSite=Lax

Set-Cookie: _shopify_fs=2021-02-25T16%3A23%3A15Z; Expires=Mon, 28-Feb-22 15:03:08 GMT; Domain=chriscoffee-dev.myshopify.com; Path=/; SameSite=Lax

CF-Cache-Status: DYNAMIC

cf-request-id: 088ac337080000e11a9422d000000001

Expect-CT: max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct

Server: cloudflare

CF-RAY: 628b07d1ab19e11a-IAD

alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400

:arrow_forward:Response Body

{“metafield”:{“id”:18765947895859,“namespace”:“specifications”,“key”:“width”,“value”:“31”,“value_type”:“string”,“description”:null,“owner_id”:4340467957811,“created_at”:“2021-02-25T13:04:17-05:00”,“updated_at”:“2021-02-25T13:04:17-05:00”,“owner_resource”:“product”,“admin_graphql_api_id”:“gid://shopify/Metafield/18765947895859”}}

Show raw log

JSONError: No data, empty input at 1:1 ^

I may have found the issue, this was in the parent folder:
main script
var jsonData = JSON.parse(responseBody);
var old = pm.environment.get(“responseData”);
old = JSON.parse(old);
// filter jsonData if needed

old.push(jsonData);
old = JSON.stringify(old);
pm.environment.set(“responseData”, old);
console.log(pm.environment.get(“responseData”));

I inherted this mes, I guess this is what is was looking for, not needed as it is working now, it just gives an error on the 201 created, where expected 200.

Thanks for you help, it made me look for any JSON request.