Last active
July 20, 2019 22:58
-
-
Save kalendar/80aad6f46660143f65a97dd192ebbdcb 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
you've got a whitespace in the assignment aarow on line 4