Problem with filtering by date

david_adam
New Member
6 0 0

I noticed that when I use the created_at_from or updated_at_from filters when querying the API, I don't get the proper result.

Example: I want to query for customers that were updated in the past hour:

/admin/api/2020-04/customers.json?updated_at_min=2020-06-22T13:00:00+02:00

I get an empty result on this. When I change the timestamp to e.g. two hours further in the past, I get a customer, but the updated_at_field matches the query string of the first query:

/admin/api/2020-04/customers.json?updated_at_min=2020-06-22T11:00:00+02:00&fields=id,created_at,updated_at

{
    "customers": [
        {
            "id": 3451882504266,
            "created_at": "2020-06-22T13:46:39+02:00",
            "updated_at": "2020-06-22T13:50:20+02:00"
        },
        {
            "id": 3451871723594,
            "created_at": "2020-06-22T13:39:52+02:00",
            "updated_at": "2020-06-22T13:43:05+02:00"
        },
        {
            "id": 2837908815946,
            "created_at": "2019-12-11T14:53:46+01:00",
            "updated_at": "2020-06-22T13:20:55+02:00"
        }
    ]
}

Is there a problem with the API? Do timestamp filters need to be calculated to a specific timezone?

0 Likes
Greg_Kujawa
Shopify Partner
965 80 204

I've run across this as well with various endpoints. If I specify the time zone in my API request as a query parameter it's ignored. Example below. Which is a quirk echoed in a few prior posts on this board :) 

 

https://community.shopify.com/c/Shopify-APIs-SDKs/Order-query-using-updated-at-min-and-updated-at-ma...

 

GET https://{my_shop}.myshopify.com/admin/customers.json?updated_at_min=2020-06-22T13:00-5:00&fields=id,created_at,updated_at HTTP/1.1
Authorization: Basic {my_access_token}
User-Agent: PostmanRuntime/7.25.0
Accept: */*
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: __cfduid=d474d283195031f2c442a1f3fcd4abe0d1591975172


HTTP/1.1 200 OK
Date: Mon, 22 Jun 2020 15:08:45 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-Sorting-Hat-PodId: 166
X-Sorting-Hat-ShopId: 23186005
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 23186005
X-ShardId: 166
X-Stats-UserId: 
X-Stats-ApiClientId: 1923396
X-Stats-ApiPermissionId: 9248702487
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
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-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://cdn.shopify.cn 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=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=140100f3-51bb-4a72-897e-70792d570330
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=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=140100f3-51bb-4a72-897e-70792d570330
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: 140100f3-51bb-4a72-897e-70792d570330
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
CF-Cache-Status: DYNAMIC
cf-request-id: 037e2c27db000083530582b200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a76e2ec9bc28353-ORD
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
Content-Length: 108

{"customers":[{"id":3734214967463,"created_at":"2020-06-22T13:16:46Z","updated_at":"2020-06-22T13:16:53Z"}]}

I have our shop defined against UTC in the admin UI, and only reference UTC in my code as a result. Unless the syntax of the timezone as a query parameter is incorrect somehow, I just made my life easier by using UTC across the board. 

0 Likes
david_adam
New Member
6 0 0

Hi @Greg_Kujawa ,

thanks for your response! It doesn't make sense to me to globally set UTC as Shop timezone, this would mean for us that we need to adjust all exports, mail templates etc.

It would be great, if the API would use the shop settings... Have I overseen this info in the documentation? I don't think so...

0 Likes
Greg_Kujawa
Shopify Partner
965 80 204

When I modified my query parameter as below then the result was what would be expected.

https://{my_shop}.myshopify.com/admin/customers.json?updated_at_min=2020-06-22T13:00:00-05:00

 

I left out the leading zero in my time offset. So now my query returns zero records, since it's not 1 PM ET yet today :) 

 

GET https://{my_shop}.myshopify.com/admin/customers.json?updated_at_min=2020-06-22T13:00:00-05:00 HTTP/1.1
Authorization: Basic {my_access_token}
User-Agent: PostmanRuntime/7.26.1
Accept: */*
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: __cfduid=d474d283195031f2c442a1f3fcd4abe0d1591975172


HTTP/1.1 200 OK
Date: Mon, 22 Jun 2020 15:41:54 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-Sorting-Hat-PodId: 166
X-Sorting-Hat-ShopId: 23186005
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 23186005
X-ShardId: 166
X-Stats-UserId: 
X-Stats-ApiClientId: 1923396
X-Stats-ApiPermissionId: 9248702487
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
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-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://cdn.shopify.cn 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=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=c5862d93-82cb-4ed1-9707-6ba9504cdaa5
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=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=c5862d93-82cb-4ed1-9707-6ba9504cdaa5
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: c5862d93-82cb-4ed1-9707-6ba9504cdaa5
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
CF-Cache-Status: DYNAMIC
cf-request-id: 037e4a83590000f2361b028200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a77137ef810f236-ORD
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
Content-Length: 16

{"customers":[]}
0 Likes