-
-
Save ryanscharf/cd9004d375321a0c79c78b709e5e57c5 to your computer and use it in GitHub Desktop.
Publishing to the Wordpress REST API from R with JSON Web Tokens and httr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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