Skip to main content

client.key_availability

Availability

Returns public information on an API Key: whether it can be used right now (available), the search contexts the key is licensed for (contexts) and the context that best matches the caller's IP address (context).

The endpoint accepts API Keys (beginning ak_) and sub-licensed keys (beginning sl_), and needs no Management Key.

A key that exists but cannot be used, because it has no lookups left or has breached a limit, returns 200 with "available": false. An unknown or malformed key returns an error.

Supply a valid Management Key and the endpoint returns the key's private details instead, as GET /keys/{key}/details does. A Management Key that does not own the key is rejected.

Endpoint​

GET /keys/{key}

See the API reference for this endpoint.

Signature​

def key_availability(key)

Arguments​

NameTypeRequiredDescription
keyStringyesAPI Key

Query Parameters​

None.

Response​

AddressZen::Responses::ApiKeyResponse. Read fields with readers named as the API names them, such as response.result, or with response["result"]. to_h returns the decoded body.

Errors​

An HTTP error raises AddressZen::ApiError with the HTTP status, the API error code and the decoded body. A transport failure raises AddressZen::TransportError. See error handling.

Example​

key-availability.rbruby
require "addresszen"

client = AddressZen::Client.new(api_key: "ak_test")

response = client.key_availability("ak_test")

puts "Available: #{response.result.available}"
puts "Context: #{response.result.context}"