Skip to content

Instantly share code, notes, and snippets.

@ryanscharf
ryanscharf / wordpress-wjt-httr.R
Created July 20, 2019 21:56 — forked from kalendar/wordpress-wjt-httr.R
Publishing to the Wordpress REST API from R with JSON Web Tokens and httr
library(httr)
# Get the JWT
get_jwt <- POST("https://example.com/throwaway/wp-json/jwt-auth/v1/token",
query = list(username = "your_username", password = "your_password"))
token <- content(get_jwt)$token
# Confirm auth is working
test <- POST("https://example.com/throwaway/wp-json/jwt-auth/v1/token/validate",
add_headers('Authorization' = paste("Bearer", token, sep = " ")), encode = "json")