Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Last active April 24, 2020 11:55
Show Gist options
  • Save openroomxyz/64927982f7ab83c79952331482df458a to your computer and use it in GitHub Desktop.
Save openroomxyz/64927982f7ab83c79952331482df458a to your computer and use it in GitHub Desktop.
Python WordPressAPI : How to create a PAGE ?
import base64, requests, json
def header(user, password):
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header_json = {'Authorization': 'Basic ' + token.decode('utf-8')}
return header_json
def create_page(content,title, url, header_json):
post = {
'title' : title,
'status' : 'publish',
'content' : content,
'categories': 5, # category ID
'date' : '2020-01-05T10:00:00'}
responce = requests.post(url + "wp-json/wp/v2/pages/" , headers=header_json, json=post)
print(responce.text)
print(json.loads(responce.content)['link'])
header_json = header("admin","XXXX XXXX XXXX XXXX XXXX XXXX") #user, application password
create_page('PIKIJAKOB','Title the piple','https://XXX.xyz/XXXX/', header_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment