Skip to content

Instantly share code, notes, and snippets.

@michellemho
Last active February 2, 2017 15:24
Show Gist options
  • Save michellemho/cb64146367b9f74bd132ae7451fe4376 to your computer and use it in GitHub Desktop.
Save michellemho/cb64146367b9f74bd132ae7451fe4376 to your computer and use it in GitHub Desktop.
InfoConnect review

Search for Companies using InfoConnect API 400m Around CARTO

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:

{
        "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"
}
@talos
Copy link

talos commented Jan 25, 2017

Looks great! I think the third & fourth questions would be worth engaging our contact at Infogroup for some clarity.

@michellemho
Copy link
Author

Information about pricing:

http://developer.infoconnect.com/faq

"You can choose any billing schedule that works for you such as weekly, monthly, quarterly or yearly billing. Please work with your sales representative to arrange a custom billing cycle. Pricing is based on the total number of records returned and the format of those records. There are 2 main types of formats: Basic and Enhanced. The basic rate is $0.04/record and the enhanced rate is $0.20/record. Please note that pricing is the same for a Business and Consumer record unless its format is different (basic vs enhanced). Infoconnect also has a weekly minimum charge of $200 per week. More details can be found in our Terms of Use."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment