We’ve migrated our documentation to a new site, which means some URLs have changed. If you hit a broken link, submit a support ticket.
Audience

Piano Insight API認証方法

概要

Piano Insight API を利用する際には、認証が必要なります。

リクエスト時に、X-cXense-Authentication をHTTPヘッダー内に含めることにより

認証を行います。詳細については、API authenticationをご参照下さい。

 

Piano Insight APIでは、下記のようなサンプルの実行例が記載されております。


python cx.py /traffic/event '{"start":-2000, "siteIds":["12345"], "filters":[{"type":"event","group":"referrerHost","item":"other.com"}], "fields":["uniqueUsers"], "groups":["url"], "count":1}'

 

ここで利用しているcx.py は、API の認証方法のページ内に記載があります。

以下は、python2.7用のcx.pyとなります。

この中の以下にユーザ情報を入力します。

 

「YOUR USER NAME」:ログインメールアドレス

「YOUR API KEY」:APIキー

APIキーは、APIキー確認方法でご確認できます。

 

Python
#!/usr/bin/python
 
import datetime
import hashlib
import hmac
import httplib
import json
  
def cx_api(path, obj, username, secret):
    body = json.dumps(obj)
    date = datetime.datetime.utcnow().isoformat() + "Z"
    signature = hmac.new(secret, date, digestmod=hashlib.sha256).hexdigest()
    headers = {"X-cXense-Authentication": "username=%s date=%s hmac-sha256-hex=%s" % (username, date, signature)}
    headers["Content-Type"] = "application/json; charset=utf-8"
    connection = httplib.HTTPSConnection("api.cxense.com", 443)
    connection.request("POST", path, json.dumps(obj), headers)
    response = connection.getresponse()
    return response.status, json.load(response)
 
if __name__ == "__main__":
    username = "YOUR USER NAME"
    secret = "YOUR API KEY"
    print(cx_api("/site", {"siteId": "YOUR SITE ID"}, username, secret))

 

 

Last updated: