LoginSignup
1
1

有料記事販売サービスBOOKERSのAPIドキュメントリニューアル、API投稿してみた

Last updated at Posted at 2024-01-14

BOOKERS開発です。
「BOOKERS」( https://bookers.tech/about/ )は低手数料・記事投稿API等、有料記事投稿者に優しいサービスを目指すプラットフォームです。

BOOKERSローンチ時から提供している定番機能「投稿用API」のドキュメント( https://bookers.tech/api/docs/ )をリニューアルしたので、使ってみた記事書いてみます。是非日々の記事販売の自動化・省力化にご活用ください!
ご意見ご要望お待ちしてます!!

API キーの取得

メニュー>アカウント設定の下部でキーを取得できます。
image.png
image.png

API投稿を試す

{token}の箇所に取得したAPIキーをコピペします。
Googleアカウントがあれば手軽にpython環境を試せるGoogle Colab( https://colab.research.google.com/?hl=ja )などで気軽に試せます。

記事投稿

import requests, json
headers = {
    'Authorization': 'Token {token}',
    'Content-Type': 'application/json',
}
data = {"title":"API投稿やってみた","category":2,"description":"記事の概要を書きます","text":"# Markdownで記事書けます!","price":500}
requests.post('https://bookers.tech/api/postcreate/', headers=headers, data=json.dumps(data))

記事投稿(下書き)

エンドポイントが異なる以外は「記事投稿(公開)」と同様です。

import requests, json
headers = {
    'Authorization': 'Token {token}',
    'Content-Type': 'application/json',
}
data = {"title":"API投稿やってみた","category":2,"description":"記事の概要を書きます","text":"# Markdownで記事書けます!","price":500}
requests.post('https://bookers.tech/api/postdraftcreate/', headers=headers, data=json.dumps(data))

記事投稿(ダウンロードコンテンツの追加)

サンプルコード(CSVを2ファイルアップロード)
{uuid}には記事のidを設定します。

import requests
XLSX_MIMETYPE = "text/csv"
files = {
  'dlc_main': ({filename_main}, open("{filepath_main}", 'rb').read(), XLSX_MIMETYPE),
  'dlc_sub01': ({filename_sub01}, open("{filepath_sub01}", 'rb').read(), XLSX_MIMETYPE),
}
req = requests.Request('PATCH', f'https://bookers.tech/api/postdlcupdate/{ uuid }/', files=files)
prepped = req.prepare()
prepped.headers['Authorization'] = f'Token {token}'
requests.Session().send(prepped)

記事更新

{uuid}には記事のidを設定します。

import requests, json
headers = {
    'Authorization': 'Token {token}',
    'Content-Type': 'application/json',
}
data = {"text":"記事更新してみた!"}
requests.patch('https://bookers.tech/api/api/postupdate/{uuid}/', headers=headers, data=json.dumps(data))

SNSキャンペーン設定

X(旧Twitter)のリポストで無料・割引などのキャンペーンを設定できます。
{uuid}には記事のidを設定します。

import requests, json
headers = {
    'Authorization': 'Token {token}',
    'Content-Type': 'application/json',
}
data = {"discount_campaign_category":"TW_RT_F","discount_campaign_tweet":"https://twitter.com/BookersOfficial/status/1733014352490553710","discount_price":0}
requests.patch('https://bookers.tech/api/postcampaignupdate/{uuid}/', headers=headers, data=json.dumps(data))

マガジン追加

{post}には記事のidを設定します。
{magazine}には記事のidを設定します。

import requests, json
headers = {
    'Authorization': 'Token {token}',
    'Content-Type': 'application/json',
}
data = {"post":"{post}", "magazine":"{magazine}"}
requests.post('https://bookers.tech/api/magazinepostcreate/', headers=headers, data=json.dumps(data))
1
1
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
1
1