Instantly share code, notes, and snippets.

Embed
What would you like to do?
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")
content(test)
# Publish page
create_page <- POST("https://example.com/throwaway//wp-json/wp/v2/pages",
add_headers('Authorization' = paste("Bearer", token, sep = " ")),
body = list(title = page_title, content = payload, status = "published"), encode = "json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment