Last active
April 24, 2020 11:55
-
-
Save openroomxyz/64927982f7ab83c79952331482df458a to your computer and use it in GitHub Desktop.
Python WordPressAPI : How to create a PAGE ?
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
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