[워드프레스] rest api JWT Auth 사용 설정 방법2 - 태그등록

[워드프레스] rest api JWT Auth 사용 설정 방법2 - 태그등록

아래와 같이 JWT Auth 를 이용하여 태그 등록을 해보도록 하겠습니다.

var token = '토큰'; writeTag(token); function writeTag(token) { fetch('http://zzz.cm/wp-json/wp/v2/tags', { method: "POST", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'Bearer ' + token }, body: JSON.stringify({ description: '태그1', name: '태그1', slug: '태그1', }) }).then(function(response){ return response.json(); }).then(function(post){ console.log(post); }); }

방금 등록된 태그 id 와 정보를 볼수 있습니다.

등록된 태그

이미 등록된 태그를 등록하려고하면 아래와 같은 내용으로 응답을 받습니다.

from http://trytoso.tistory.com/1530 by ccl(A) rewrite - 2021-10-18 13:25:05