4-1. Tellus Market API (for developers)

Select the product you want to use in the market and make a purchase. Details on how to purchase are provided in the user guide.

20200219_000198_image2.png

1.Purchase

Select the product you want to use in the market and make a purchase. Details on how to purchase are provided in the user guide.(https://www.tellusxdp.com/ja/market-service/service/guide/)

2.Confirm "Product ID"

After purchasing a product, you can check the "Product ID" from the "Purchased" product list in the dashboard.

20200219_000198_image3.png

3. Issue a market token

To use the API purchased in the market, you need to issue a market token.

import requests, datetime, json
TOKEN = 'ダッシュボードでAPIアクセストークンを発行しここに貼り付けます'
product_id = '利用したいAPIの商品ID'
# マーケットトークン有効期限(30分後に設定)
# デフォルトでは5分、最長で60分まで設定可能
expires_at = (datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=+9))) + datetime.timedelta(minutes=30)).isoformat()
def get_market_token(payload={}):
    url = 'https://sdk.tellusxdp.com/api/manager/v2/auth/token/'
    headers = {
        'Authorization': 'Bearer ' + TOKEN,
        'Content-type': 'application/json'    }
    r = requests.post(url, headers=headers, data=json.dumps(payload))
    if r.status_code is not 200:
        raise ValueError('status error({}).'.format(r.status_code))
    return json.loads(r.content) 
# マーケットトークンを発行する
ret = get_market_token({'product_id': provider_id, 'expires_at':expires_at})
print('token api result : {}'.format(ret))
'''
token api result : {
  'product_id': 'sample',
  'expires_at': '2020-02-28T10:00:00+09:00', 
  'token': 'xxx',
  'base_url': 'https://example.com'
}
'''

When executing the market token issuing API, an API access token is required. API access tokens can be issued from the "development environment" on the dashboard kidimage1.png You will get a 401 error when trying to issue a market token with information of a product that you have not purchased. After the expiration period set at the time of issuance (up to 60 minutes) is over, the market token will become unusable. Please reissue if necessary. For more information on the Market Token Issuing API, see (https://www.tellusxdp.com/docs/api-reference/tools-v2.html). ## 4.API request Make an API request using the issued market token.

import requests, datetime, json
TOKEN = 'ダッシュボードでAPIアクセストークンを発行しここに貼り付けます'
product_id = '利用したいAPIの商品ID'
path= '利用したいAPIのAPIリファレンスからpathを調べて貼り付けます'
# マーケットトークン有効期限(30分後に設定)
# デフォルトでは5分、最長で60分まで設定可能
expires_at = (datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=+9))) + datetime.timedelta(minutes=30)).isoformat()
def get_market_token(payload={}):
    url = 'https://sdk.tellusxdp.com/api/manager/v2/auth/token/'
    headers = {
        'Authorization': 'Bearer ' + TOKEN,
        'Content-type': 'application/json'    }
    r = requests.post(url, headers=headers, data=json.dumps(payload))
    if r.status_code is not 200:
        raise ValueError('status error({}).'.format(r.status_code))
    return json.loads(r.content) 
def exec_api(url, token, payload={}):
    headers = {
        'Authorization': 'Bearer ' + token
    }
    r = requests.get(url, headers=headers, params=payload)
    return r.content
# マーケットトークンを発行する
ret = get_market_token({'product_id': product_id, 'expires_at':expires_at})
# API実行
executed = exec_api(ret['base_url'] + path, ret['token'], {})
print('executed : {}'.format(executed))

If the token is invalid or expired, a 401 error will be generated. It is recommended that the base_url of the API refers to the return value of the token-issuing API. The path should be checked in the API reference of each product.

Next