Skip to content

Instantly share code, notes, and snippets.

View geofflambeth's full-sized avatar

Geoffrey Lambeth geofflambeth

View GitHub Profile
@jdembowski
jdembowski / wp-rest-api-example.py
Last active January 17, 2024 21:07
Use cookie authentication to obtain a nonce for WP REST API calls that need authentication.
#!/usr/bin/python3
# This Python script will
#
# - Log into a WordPress installation using supplied credentials.
# - Get a single published post using the REST call /wp/v2/posts
# - Get a valid nonce from '/wp-admin/post.php?post=xxx&action=edit'
# - Use cookie+nonce to retrieve on post in draft status via REST.
#
# Getting that valid nonce must be performed prior to each WP REST call