shoaib-santo

WordPress Rest API

Sep 27th, 2024 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | Source Code | 0 0
  1. import base64
  2. import requests
  3. import json
  4.  
  5. wp_user = "santosarker00@gmail.com"
  6. wp_password = "Eu5l dNYx qpnr KkOP TRWx QrgD"
  7. wp_credential = f"{wp_user}:{wp_password}"
  8. wp_token = base64.b64encode(wp_credential.encode()).decode()
  9. wp_headers = {"Authorization": f"Basic {wp_token}"}
  10.  
  11. url = "https://dev-shoaibsanto.pantheonsite.io/wp-json/wp/v2/posts"
  12.  
  13. data = {
  14.     "title": "Sample Title",
  15.     "content": "Sample Content",
  16.     "slug": "sample-url",
  17.     "status": "publish"
  18. }
  19.  
  20. # Send a POST request with headers and JSON data
  21. res = requests.post(url, headers=wp_headers, json=data, verify=False)
  22.  
  23. print(res.status_code)
  24. print(res.text)
  25.  
Add Comment
Please, Sign In to add comment