Create an API key on Tether
Knowledge Base
Create an API key on Tether
How to create an API key on Tether.to
How to create Authenticated Requests on Tether.to
Ruby
require 'time'
require 'httparty'
@base_uri = 'https://app.tether.to/api/v1'
@api_key = 'YOUR-KEY'
@api_secret = 'YOUR-SECRET'
def b64_encode(string)
Base64.strict_encode64(string)
end
def md5_base64digest(string)
Digest::MD5.base64digest(string)
end
def hmac_signature(canonical_string)
digest = OpenSSL::Digest.new('sha1')
b64_encode(OpenSSL::HMAC.digest(digest, @api_secret, canonical_string))
end
def do_request(verb, uri, options={})
path = @base_uri + uri
if [:get, :delete].include? verb
request_options = {}
path = "#{@base_uri}#{uri}?#{URI.encode_www_form(options)}" unless options.empty?
content_md5 = ''
else
body = options.to_json
request_options = { body: body }
content_md5 = md5_base64digest(body)
end
# Generate valid headers and signature
headers = {
'Content-MD5' => content_md5,
'Date' => Time.now.utc.httpdate,
'Content-Type' => 'application/json',
}
canonical_string = [ verb.upcase,
headers['Content-Type'],
headers['Content-MD5'],
URI(@base_uri + uri).path,
headers['Date']
].join(',')
signature = hmac_signature(canonical_string)
headers['Authorization'] = "APIAuth #{@api_key}:#{signature}"
request_options[:headers] = headers
# forward to HTTParty
response = HTTParty.send(verb, path, request_options)
parsed_response = JSON.parse(response.body)
parsed_response
end
def get(path, options={})
do_request :get, path, options
end
## Define the functions to perform the authenticated calls
# returns current account balances
def balances
get '/balances.json'
end
# returns list of most recent transactions
def transactions
get '/transactions.json'
end
# returns specific page of transactions
def transactionPage(page)
get "/transactions/page/#{page}"
end
# returns details of a specific transaction
def get_transaction(id)
get "/transactions/#{id}.json"
end
Python
import requests, urllib, json
import base64, hashlib, hmac
import time
base_uri = 'https://app.tether.to/api/v1'
api_key = ''
api_secret = ''
def b64_encode(string):
try:
return base64.b64encode(string.encode()).decode()
except:
return base64.b64encode(string).decode()
def md5_base64digest(string):
try:
return b64_encode(hashlib.md5(string.encode()).digest())
except:
return b64_encode(hashlib.md5(string).digest())
def hmac_signature(canonical_string):
return b64_encode(hmac.new(api_secret.encode(),canonical_string.encode(),hashlib.sha1).digest())
def do_request(verb, uri, options={}):
path = base_uri + uri
if verb in ['get', 'delete']:
request_options = {}
encoded_options=""
if len(options) > 0:
encoded_options = urllib.parse.urlencode(options)
path = base_uri+uri+encoded_options
content_md5 = ''
else:
body = json.dumps(options)
request_options = { 'body': body }
content_md5 = md5_base64digest(body)
# Generate valid headers and signature
headers = {
'Content-MD5' : content_md5,
'Date': time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime()),
'Content-Type' : 'application/json',
}
canonical_string = (',').join([ verb.upper(),
headers['Content-Type'],
headers['Content-MD5'],
urllib.parse.urlparse(base_uri + uri).path,
headers['Date']
])
signature = hmac_signature(canonical_string)
headers['Authorization'] = "APIAuth "+api_key+":"+signature
request_options['headers'] = headers
response = requests.get(path, headers=headers)
parsed_response = response.json()
return parsed_response
def get(path, options={}):
return do_request('get', path, options)
## Define the functions to perform the authenticated calls
# returns current account balances
def balances():
return get('/balances.json')
# returns list of most recent transactions
def transactions():
return get('/transactions.json')
# returns specific page of transactions
def transactionPage(page):
return get("/transactions/page/"+str(page))
# returns details of a specific transaction
def get_transaction(id):
return get("/transactions/"+str(id)+".json")
If you have any questions feel free to contact Tether Support for further assistance. The Future of Money
Sign UpDriving the Future of Money
Tether supports and empowers growing ventures and innovation throughout the blockchain as a digital token built on multiple blockchains.