headers
- アプリケーションパスワードはwordpress管理画面のuserページより取得可能
const headers = {
"Content-Type": "application/json",
Authorization:
"Basic " + Buffer.from(`${wordpressのユーザーネーム}:${wordpressのアプリケーションパスワード}`).toString("base64"),
};
url
const url = `${wordpressのURL}/wp-json/wp/v2/posts`;
articleData(投稿内容)
- 公開ステータスは以下
- publish(公開)
- future(公開予約)
- draft(下書き)
- pending(非公開)
- private(限定公開)
const articleData = {
title: 記事タイトル,
content: 記事本文,
status: 公開ステータス,
};
API実行
const result = await axios.post(url, articleData, { headers });
レスポンス内から投稿ページリンクを参照
const postedURL = result.data.link
以上