Retrieve a list of NAICS codes for a given list of POIs using batch_lookup and the relevant Placekeys.

query($placekeys: [Placekey!]) {
  batch_lookup(placekeys: $placekeys) {
    placekey
    safegraph_core {
      location_name
      street_address
      city
      region
      postal_code
      iso_country_code
      naics_code
      top_category
      sub_category
    }
  }
}
curl --location --request POST 'https://api.safegraph.com/v1/graphql' \
--header 'apikey: {your-api-key}' \
--header 'content-type: application/json' \
--data-raw '{"query":"query($placekeys: [Placekey!]) {\n  batch_lookup(placekeys: $placekeys) {\n    placekey\n    safegraph_core {\n      location_name\n      street_address\n      city\n      region\n      postal_code\n      iso_country_code\n      naics_code\n      top_category\n      sub_category\n    }\n  }\n}","variables":{"placekeys":["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]}}'
# pip install safegraphQL
import safegraphql.client as sgql

sgql_client = sgql.HTTP_Client(apikey = 'your-api-key')

pks = [
    "[email protected]",
    "[email protected]",
    "[email protected]",
    "[email protected]",
    "[email protected]"
  ]
cols = [
    'location_name',
    'street_address',
    'city',
    'region',
    'postal_code',
    'iso_country_code',
    'naics_code',
    'top_category',
    'sub_category'
]

sgql_client.lookup(product = 'core', placekeys = pks, columns = cols)
{
  "data": {
    "batch_lookup": [
      {
        "placekey": "[email protected]",
        "safegraph_core": {
          "location_name": "Patrick Baptist Church",
          "street_address": "2006 Parkinson Rd",
          "city": "Ferris",
          "region": "TX",
          "postal_code": "75125",
          "iso_country_code": "US",
          "naics_code": 813110,
          "top_category": "Religious Organizations",
          "sub_category": "Religious Organizations"
        }
      },
      {
        "placekey": "[email protected]",
        "safegraph_core": {
          "location_name": "United States Postal Service (USPS)",
          "street_address": "317 E Main St",
          "city": "Edmore",
          "region": "MI",
          "postal_code": "48829",
          "iso_country_code": "US",
          "naics_code": 491110,
          "top_category": "Postal Service",
          "sub_category": "Postal Service"
        }
      },
      {
        "placekey": "[email protected]",
        "safegraph_core": {
          "location_name": "Private Ink",
          "street_address": "333 Peterson Rd Ste 250",
          "city": "Libertyville",
          "region": "IL",
          "postal_code": "60048",
          "iso_country_code": "US",
          "naics_code": 812199,
          "top_category": "Personal Care Services",
          "sub_category": "Other Personal Care Services"
        }
      },
      {
        "placekey": "[email protected]",
        "safegraph_core": {
          "location_name": "Little Italy Pizza Cafe",
          "street_address": "16A N State St",
          "city": "Greenfield",
          "region": "IN",
          "postal_code": "46140",
          "iso_country_code": "US",
          "naics_code": 722511,
          "top_category": "Restaurants and Other Eating Places",
          "sub_category": "Full-Service Restaurants"
        }
      },
      {
        "placekey": "[email protected]",
        "safegraph_core": {
          "location_name": "Tolenas Elementary",
          "street_address": "4500 Tolenas Rd",
          "city": "Fairfield",
          "region": "CA",
          "postal_code": "94533",
          "iso_country_code": "US",
          "naics_code": 611110,
          "top_category": "Elementary and Secondary Schools",
          "sub_category": "Elementary and Secondary Schools"
        }
      }
    ]
  },
  "extensions": {
    "row_count": 5,
    "version_date": "1627739802__2021_07"
  }
}