Creación de clave API en Tether.to

Knowledge Base

Creación de clave API en Tether.to

An API key (application programming interface key) is a code that serves as a unique identifier and authentication mechanism for accessing and using an API. In other words, an API Key is a unique credential to authenticate requests linked to your account.

The Authenticated API on Tether.to grants you restricted access to your Tether account on the platform, allowing you to retrieve limited account data.

How to create an API key on Tether.to

  1. Firstly sign in to your Tether.to account. 

  2. Then navigate to your account settings and look for the API keys tab.

  3. In there, select the Create Key button and select the desired permissions.

  4. Select the desired permissions and click on the Create new API key button.

Note: You can generate new API keys and revoke current ones from this page.

How to create Authenticated Requests on Tether.to

Authentication is achieved through the signing of the request details with the user API secret and then passing the API key and base 64 encoded signature in the header along with the request to be verified.

Below are examples in Ruby and Python for interacting with authenticated endpoints. 

The following assumptions are made:

  • You are using your API key and API Secret key;

  • Your signature variable follows the same format that is listed below.

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 = md5_base64digest('')

  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 = md5_base64digest('')
  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

Registrarte

Driving the Future of Money

Tether supports and empowers growing ventures and innovation throughout the blockchain as a digital token built on multiple blockchains.

Derechos de autor © 2013 - 2024 Tether Operaciones Limitadas. Todos los derechos reservados.
instagram mono
twitter mono
telegram mono
linkedin mono
facebook mono
reddit mono