• Plans & Pricing
  • Log in
  • Get started
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress 
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Get started
  • Sign up
  • Log in
About
  • Plans & Pricing
Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress  
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Jetpack App
  • Learn more
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Search
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Forums / WordPress API Authentication Error

WordPress API Authentication Error

  • Unknown's avatar
    kwill5800 · Member · Apr 10, 2023 at 2:22 am
    • Copy link Copy link
    • Add topic to favorites Add topic to favorites

    Im trying to use the wordpress API to create a blog post on my site but when I run the below code I get a 401 user not able to create posts error even though I am the site admin.

    import requests

    import base64

    wordpress_user = “Username”

    wordpress_password = “Password”

    wordpress_credentials = wordpress_user + “:” + wordpress_password

    wordpress_token = base64.b64encode(wordpress_credentials.encode())

    wordpress_header = {‘Authorization’: ‘Basic ‘ + wordpress_token.decode(‘utf-8’)}

    def create_wordpress_post():

    api_url = ‘https://kwonsoft.blog/wp-json/wp/v2/posts’

    data = {

    ‘title’ : ‘Example wordpress post’,

    ‘status’: ‘draft’,

    ‘slug’ : ‘example-post’,

    ‘content’: ‘This is the content of the post’

    }

    response = requests.post(api_url,headers=wordpress_header, json=data)

    print(response)

    create_wordpress_post()

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar
    staff-totoro · Staff · Apr 10, 2023 at 10:24 pm
    • Copy link Copy link

    Hi there,

    Although support staff is familiar with API useage we are not trained developers and will not be able to troubleshoot your code directly. However, its’ worth noting that sites on our managed hosting use a custom login system (for enhanced security) so it may be the case that if you are using the developer API here certain user commands will not work due to this difference. https://developer.wordpress.org/rest-api/

    Instead you may wish to see if you can accomplish this using the wordpress.com-specific APIs here instead of the wordpress.org API: https://developer.wordpress.com/docs/api/

    If you must use the wordpress.org API, you can turn off our secure login system by disabling SSO on your site. The steps to do this are found here.

    Please note that the above instructions will walk you through how to create a wp-admin login for your site, which you will want to be sure to do before turning off SSO. Once SSO is inactive you will not connect to your site dashboard using your WordPress.com account, but by entering a second login that you set using the steps above.

    Hope that helps. Please let us know if you have any more questions.

  • The topic ‘WordPress API Authentication Error’ is closed to new replies.

Tags

  • account
  • API
  • design
  • import
  • Jetpack

About this topic

  • In: Support
  • 2 participants
  • 1 reply
  • Last activity 3 years
  • Latest reply from kwill5800

Couldn't find what you needed?

Contact us

Contact us

Get answers from our AI assistant, with access to 24/7 expert human support on paid plans.

Browse our guides

Browse our guides

Find step-by-step solutions to common questions in our comprehensive guides.

WordPress.com

Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Professional Email
  • Website Design Services
  • WordPress Studio
  • Enterprise WordPress
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • WordPress.com Blog
  • Business Name Generator
  • Logo Maker
  • WordPress.com Reader
  • Accessibility
  • Remove Subscriptions
Help
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
  • Developer Resources
Company
  • About
  • Press
  • Terms of Service
  • Privacy Policy
  • Do Not Sell or Share My Personal Information
  • Privacy Notice for California Users
DeutschEspañolFrançaisBahasa IndonesiaItalianoNederlandsPortuguês do BrasilSvenskaTürkçeРусскийالعربيةעִבְרִית日本語한국어简体中文繁體中文English

Mobile Apps

  • Download on the App Store
  • Get it on Google Play

Social Media

  • WordPress.com on Facebook
  • WordPress.com on X (Twitter)
  • WordPress.com on Instagram
  • WordPress.com on YouTube

Automattic

Automattic
Work With Us
    • WordPress.com Forums
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • Manage subscriptions