Skip to content

Instantly share code, notes, and snippets.

@FloPinguin
Created December 30, 2021 16:29
Show Gist options
  • Save FloPinguin/5df1cb0b7e2f7021e1256383141bf883 to your computer and use it in GitHub Desktop.
Save FloPinguin/5df1cb0b7e2f7021e1256383141bf883 to your computer and use it in GitHub Desktop.
How to update wordpress.com posts via API
import requests
# https://stackoverflow.com/questions/48589954/can-i-use-the-rest-api-for-a-site-hosted-on-wordpress-com
# https://developer.wordpress.com/docs/oauth2/
# https://developer.wordpress.com/apps/
access_token = requests.post("https://public-api.wordpress.com/oauth2/token", data={
'client_id': <Redacted>,
'client_secret': '<Redacted>',
'grant_type': 'password',
'username': '<Redacted>',
'password': '<Redacted>',
}).json()['access_token']
# https://developer.wordpress.com/docs/api/console/
# https://developer.wordpress.org/rest-api/reference/posts/
a = requests.post('https://public-api.wordpress.com/rest/v1.1/sites/<Redacted>/posts/<Redacted>', headers={
'Authorization': 'BEARER ' + access_token
}, data = {
'content': '<Redacted>'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment