Final Result: https://team.carto.com/u/michellemho-carto/builder/6387de8e-e1b5-11e6-9b71-0ee66e2c9693/embed
Criteria search that goes into POST content body:
{
"RadiusCenterPointList" :
[
{ "Latitude" : "40.704301",
"Longitude" : "-73.936658",
"RadiusMiles" : ".25"}
],
"ResourceType": "Enhanced",
"Limit":100
}
Problem: the maximum limit for "Enhanced" resource types is 100 per query. Solution: offsets!
Python Code:
import json
import pandas as pd
from urllib import urlencode
import requests
base_url = 'https://api.infoconnect.com/v1/companies/search'
apikey = [INSERT APIKEY]
params = {'apikey':apikey}
final_geojson_features = []
final_data = []
n = 0
data = [1]
while len(data) > 0:
payload = {
"RadiusCenterPointList" :
[{"Latitude" : "40.704301",
"Longitude" : "-73.936658",
"RadiusMiles" : ".25"}],
"ResourceType": "Enhanced",
"Limit":100,
"Offset":n
}
r = requests.post(base_url, json=payload, params=params)
data = r.json()
for i in data:
final_data.append(i)
n += 100
features = []
for d in final_data:
try:
coded = {
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": [d["Location"]["Longitude"], d["Location"]["Latitude"]],
},
"properties" : d,
}
features.append(coded)
except KeyError:
pass
geojson = {
"type": "FeatureCollection",
"features": features
}
outfile = 'infoconnect_4.json'
with open(outfile, 'w') as f:
json.dump(geojson, f)
GeoJSON Test: http://geojsonlint.com/
Import .json file into CARTO, and voilà!
https://team.carto.com/u/michellemho-carto/builder/6387de8e-e1b5-11e6-9b71-0ee66e2c9693/embed
##Questions:
-
What is the difference between "ResourceType": Basic, Core, and Enhanced? Answer: http://redesign-infogroup.devportal.apigee.com/guide/resource-types What is a Custom type? Does that change pricing?
The most basic record is the ‘Core’ record and it looks like this: https://api.infoconnect.com/v1/companies/719342925?resourceType=core Result:
{
"ETag": "b8cc3f99",
"Id": "719342925",
"Links": [
{
"Href": "/v1/companies/719342925",
"Rel": "self"
},
{
"Href": "/v1/companies/452186299",
"Rel": "parent"
}
],
"ParentCompany": "452186299"
}
Both ETag and Id are internal record ids that uniquely identify this particular record. The 'Id' field is especially usfull because you can use it in a call to the get API for companies or people to retrieve this particular record again. The same goes for ‘ParentCompany’ if this company has one. In fact, you can see in the ‘Links’ array, we return these exact URIs for both this record and the parent company record (if there is one).
So that is the 'Core' record. It contains just the most basic identifier for the data. The next type of format is the ‘Basic’ record and builds on the 'Core' record to include more information. Below is an example of what this looks like for the same company: https://api.infoconnect.com/v1/companies/719342925?resourceType=basic Result:
{
"ETag": "4e9b0263",
"Id": "719342925",
"Links": [
{
"Href": "/v1/companies/719342925",
"Rel": "self"
},
{
"Href": "/v1/companies/452186299",
"Rel": "parent"
}
],
"Address": "777 Brockton Ave", "AddressParsed": { "Name": "Brockton", "Number": "777", "Suffix": "Ave" }, "City": "Abington", ""CompanyName": "SUBWAY", "FirstName": "J", "LastName": "Leone", "Location": { "Latitude": 42.096019, "Longitude": -70.967567 }, "Phone": "7814212014", "PostalCode": "02351", "StateProvince": "MA",
"ParentCompany": "452186299"
}
The next step up from Basic is the ‘Enhanced’ record. This record, again, builds on the Core and Basic and includes even more information. https://api.infoconnect.com/v1/companies/719342925?resourceType=enhanced Result:
{
"ETag": "c8ce34a6",
"Id": "719342925",
"Links": [
{
"Href": "/v1/companies/719342925",
"Rel": "self"
},
{
"Href": "/v1/companies/452186299",
"Rel": "parent"
}
],
"Address": "777 Brockton Ave",
"AddressParsed": {
"Name": "Brockton",
"Number": "777",
"Suffix": "Ave"
},
"City": "Abington",
"CompanyName": "SUBWAY",
"FirstName": "J",
"LastName": "Leone",
"Location": {
"Latitude": 42.096019,
"Longitude": -70.967567
},
"Phone": "7814212014",
"PostalCode": "02351",
"StateProvince": "MA",
"BusinessType": "Restaurants", "County": "Plymouth", "CreditRatingScore": "B+", "Franchise": "Subway", "Gender": "Male", "LocationEmployeesSizeActual": 7, "LocationEmployeesSizeRange": "5-9", "LocationSalesVolumeActual": 406000, "LocationSalesVolumeRange": "Less Than $500,000", "NaicsList": [ { "Code": "72251301", "Description": "Limited-Service Restaurants" }, { "Code": "72251117", "Description": "Full-Service Restaurants" }, { "Code": "72251302", "Description": "Limited-Service Restaurants" }, { "Code": "72251303", "Description": "Limited-Service Restaurants" } ],
"ParentCompany": "452186299",
"PrimaryNaics": "72251117", "PrimarySic": "581208", "SicList": [ { "Code": "581206", "Description": "Foods-Carry Out", "YearFirstAppeared": "2009" }, { "Code": "581208", "Description": "Restaurants", "YearFirstAppeared": "2009" }, { "Code": "581209", "Description": "Delicatessens", "YearFirstAppeared": "2009" }, { "Code": "581219", "Description": "Sandwiches", "YearFirstAppeared": "2009" } ], "Title": "Owner", "UriList": [ { "Uri": "subway.com" } ], "ZipPlus4": "02351-2111"
}
Like SIC codes that this company has been assigned, employee size, sales volume, and credit score.
So far all these examples have applied to companies, but people also have the same kinds of records, each with more and more information returned with them. Check out the people api pages [http://developer.infoconnect.com/post-search-0#tabs-4] for all the details on those!
One final thing before we finish is that while these types are basically fixed in what data they will return, the APIs also support what is essentially a custom record. Using the 'Fields' parameter in a POST request and omitting the ResourceType paramter you can get only the data back that you want! So, for example, if you only want the company name, geo location, and phone number you could make a POST request like this: POST https://api.infoconnect.com/v1/companies/search?apikey= Body:
{
"Id":["719342925"],
"Fields":["CompanyName","Location","Phone"]
}
The result will be a ‘Core’ record along with the fields you requested.
{
"ETag": "7148eab3",
"Id": "719342925",
"Links": [
{
"Href": "/v1/companies/719342925",
"Rel": "self"
},
{
"Href": "/v1/companies/452186299",
"Rel": "parent"
}
],
"CompanyName": "SUBWAY", "Location": { "Latitude": 42.096019, "Longitude": -70.967567 }, "Phone": "7814212014",
"ParentCompany": "452186299"
}
- What does it mean that "Location" is a "Royalty field"? http://redesign-infogroup.devportal.apigee.com/api/companies-post-search#location
- Why are there points that do NOT have Location (Lat/Long)? How many (percent estimate) have no location? In this sample of 400m around CARTO, it looks like there are 318 records found, but only 224 with Lat/Long locations
- Why are the results different from the previous static sample set we received? In that sample set, 822 business locations were found in the 400m radius. https://team.carto.com/u/michellemho-carto/builder/3692db28-adb1-11e6-b882-0e98b61680bf/embed
Looks great! I think the third & fourth questions would be worth engaging our contact at Infogroup for some clarity.