0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sakura.ioにAPI経由でモジュールを登録する

0
Posted at

sakura.ioのAPIを使ってモジュールを登録する。モジュールの登録は POST https://api.sakura.io/v1/modules/ として行う。 (APIドキュメント)

事前作業

APIキーの発行

sakura.ioコンソールにログインしてAPIキーを発行します。

右上のプルダウンから「APIキー」を開き…

image.png

「APIキー追加」を進めます。

image.png

「全権限」で作成。TokenとSecretを控えましょう。

image.png

プロジェクト作成

「プロジェクトを追加」します。

image.png

プロジェクトの番号を控えます。
image.png

CSVを作る

登録名称, registerId, registerPass の形でCSVを作る。

sakuraio.csv
name,REGISTER_ID,REGISTER_PASS

コード

次のコードでまとめて取り込む。

import csv
import requests
from requests.auth import HTTPBasicAuth

TOKEN = '<INPUT_YOUR_TOKEN_HERE>'
SECRET = '<INPUT_YOUR_SECRET_HERE>'
PROJ_ID = <INPUT_PROJECT_ID_HERE>


reader = csv.reader(open('sakuraio.csv', 'r'))
url = 'https://api.sakura.io/v1/modules/'


for name, register_id, register_pass in reader:
  d = {
    'project': PROJ_ID,
    'name': name,
    'register_id': register_id,
    'register_pass': register_pass,
  }

  res = requests.post(url, json=d, headers={'Content-Type': 'application/json'}, auth=HTTPBasicAuth(TOKEN, SECRET))
  print(res)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?