The "sub selection" error when calling visits_by_day and visits_by_each_hour variables from weekly patterns using "search" query

Hi everyone, I was trying to get the weekly pattern data for a certain category of industry (grocery stores) from a location. I wanted to get visits_by_day and visits_by_each_hour variables, however, I got the following error messages:

Field ‘visits_by_day’ of type ‘[VisitsBy!]’ must have a sub selection

Field ‘visits_by_each_hour’ of type ‘[VisitsBy!]’ must have a sub selection

I found it a bit odd given other variables can be returned without any issues and that the example code regarding weekly pattern data, which also asked for these two variables, worked well without the need to make sub selections. I wonder if the reason is that I changed the API site from 'https://api.safegraph.com/v1/graphql' to 'https://api.safegraph.com/v2/graphql' or that I used search query instead of lookup query.

The code is attached here for your reference:

query = """
query {
    search(filter: {
        address: {
            city: "Baltimore",
            region: "MD",
            iso_country_code: "US"
        }
        naics_code: 4451
    }) {
        places {
            results(first: 10, after: "") {
                edges {
                    node {
                        placekey
                        safegraph_core {
                                    location_name
                                    street_address
                        }
                        safegraph_weekly_patterns(date: "2021-02-10") {
                            date_range_start
                            date_range_end
                            visitor_home_cbgs
			                visits_by_day
                            visits_by_each_hour
                        }
                    }
                }
            }
        }
    }
}
"""


req = requests.post(
    'https://api.safegraph.com/v2/graphql',
    json={
        'query': query
    },
    headers=headers
)

Many thanks for your help in advance!

1 Like

Looping in @vchen who can help with this!

1 Like

Any updates on this?