Skip to main content

client.key_usage

Usage Stats

Reports the number of lookups a key consumed over a date range, as a total and a daily breakdown.

The range defaults to the last 21 days. start and end take UNIX timestamps in milliseconds, and end defaults to the current time. The maximum range is 90 days.

Query at most three tags at once.

Endpoint​

GET /keys/{key}/usage

See the API reference for this endpoint.

This operation needs a Management Key. Pass it as management_key: to IdealPostcodes::Client.new, which sends it in the Authorization header. See setup.

Signature​

def key_usage(key, start: nil, end: nil, tags: nil, licensee: nil)

Arguments​

NameTypeRequiredDescription
keyStringyesAPI Key
keywordskeyword argumentsnoOne per query parameter, named as the API names them. A keyword left out or nil is not sent.

Query Parameters​

Pass these as keyword arguments.

NameTypeRequiredDescription
startIntegernoStart Timestamp
endIntegernoEnd Timestamp
tagsString, Array<String>noTags
licenseeStringnoLicensee Key

Response​

IdealPostcodes::Responses::ApiKeyUsageResponse. 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 IdealPostcodes::ApiError with the HTTP status, the API error code and the decoded body. A transport failure raises IdealPostcodes::TransportError. See error handling.

Example​

key-usage.rbruby
require "ideal_postcodes"

client = IdealPostcodes::Client.new(api_key: "ak_test", management_key: "uk_test")

now = (Time.now.to_f * 1000).to_i
week = 7 * 24 * 60 * 60 * 1000

response = client.key_usage("ak_test", start: now - week, end: now)

response.result.daily_count.each do |day|
puts "#{day.date}: #{day.count}"
end

puts "Total: #{response.result.total}"