Ruby access to the API
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status Code Climate Test Coverage Issue Count


Ruby access to the API.


To get started, you'll need an API key from


Set the API key as the environment variable 'DATA_DOT_GOV_API_KEY' or pass the key as an argument:

require 'samwise'

client = 'my key ...')

# if you set the 'DATA_DOT_GOV_API_KEY' env var, just use:
client =

Get summary info in a single request

client.get_vendor_summary(duns: '080037478')
  in_sam: true,
  small_business: true

Note: the definition of small_business is IT-centric.

See Verify Vendor is a small business for the list of NAICS codes uses to check if some a vendor is a small business.

Verify DUNS number is in

client.duns_is_in_sam?(duns: '080037478')
#=> true

Verify Vendor is not on the excluded parties list

client.excluded?(duns: '080037478')
#=> false

Verify Vendor is a small business

client.small_business?(duns: '080037478')
#=> false

This method checks against the following NAICS codes:

  • 511210
  • 541511
  • 541512
  • 541519
  • 334614

What is a NAICS code?

The North American Industry Classification System (NAICS) is used by businesses and governments to classify and measure economic activity in the United States, Canada, and Mexico. NAICS is 6-digit code system that is currently the standard used by federal statistical agencies in classifying business establishments.


The whitelisted NAICS codes classify companies that offer IT or related services.

Get DUNS info

duns_info = client.get_duns_info(duns: '080037478')

          "line1"=>"4301 N HENDERSON RD APT 408",
      "activationDate"=>"2015-10-30 11:42:30.0",
      "registrationDate"=>"2015-10-28 00:00:00.0",
      "expirationDate"=>"2016-10-27 10:53:02.0",
      "corporateStructureName"=>"Sole Proprietorship",
      "legalBusinessName"=>"Sudol, Brendan",
      "congressionalDistrict"=>"VA 08",
      "lastUpdateDate"=>"2015-11-02 17:36:23.0",
        "line1"=>"4301 N Henderson Rd Apt 408",
      "submissionDate"=>"2015-10-28 10:53:02.0",
          "line1"=>"4301 N HENDERSON RD APT 408",
        "line1"=>"4301 N Henderson Rd Apt 408",

Validate the format of a DUNS number

This does not need an API key and makes no network calls.

Samwise::Util.duns_is_properly_formatted?(duns: '88371771')
#=> true

Samwise::Util.duns_is_properly_formatted?(duns: '883717717')
#=> true

Samwise::Util.duns_is_properly_formatted?(duns: '0223841150000')
#=> true

Samwise::Util.duns_is_properly_formatted?(duns: '08-011-5718')
#=> true

Samwise::Util.duns_is_properly_formatted?(duns: 'abc1234567')
#=> false

Samwise::Util.duns_is_properly_formatted?(duns: '1234567891234567890')
#=> false

Format a DUNS number

This removes any hyphens and appends 0s where appropriate (does not need an API key and makes no network calls):

Samwise::Util.format_duns(duns: '08-011-5718')
#=> "0801157180000"

duns can be a 7, 8, 9, or 13 digit number (hyphens are removed):

  • If it is 7 digits, 00 is prepended, and 0000 is added to the end.
  • If it is 8 digits, 0 is prepended, and 0000 is added to the end.
  • If it is 9 digits, 0000 is added to the end.
  • If it is 13 digits, the number is unchanged.

Check status in

There is a web form where anyone can enter a DUNS number to get its status within

This form uses an undocumented/unpublished JSON endpoint. This gem provides Ruby access to that endpoint.

This does not require an API key, but it will make a network call to the above URL.

The status web form hard codes what appears to be an API key. That key is used by default in this gem. However, you may supply your own (also tell us where you got it!).

client =  'optional')
client.get_sam_status(duns: '08-011-5718')

#=> {
  "Message" => "Request for registration information forbidden",
  "Code" => 403,
  "Error" => ""

client.get_sam_status(duns: )


In your Gemfile:

gem 'samwise', github: '18f/samwise'

Coming Soon

$ gem install samwise

Command Line Interface

The samwise gem can be run via command line via a piped in file or with a file input flag.

To make the gem executable run gem install samwise which calls makes the contents of the bin directory executable in the gemspec.

Input Format

The CLI expects a .json with the following schema:

{"users":[{"other_keys": "other_values", "duns":"duns_number"}]}

If the JSON does not include a "duns" key, the CLI will abort.

The JSON can be piped in or fed in from a file via a -i flag. For example:

cat "input_file.json" | samwise verify > output.json
samwise verify -i "input_file.json" > output.json


The CLI will output a JSON to STDOUT with an addition key to be determined by the method run (see below for reference).

Available Commands

CLI Comand Samwise Function JSON OutKey
samwise verify Samwise::Client.duns_is_in_sam? verified
samwise excluded Samwise::Client.excluded? excluded
samwise get_info Samwise::Client.get_duns_info sam_data
samwise check_format Samwise::Util.duns_is_properly_formatted? valid_format
samwise format Samwise::Util.format_duns formatted_duns

Public Domain

This project is in the worldwide public domain. As stated in CONTRIBUTING:

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.