Wordpress api11/22/2023 Other v2 APIs that can be queried are listed here. The example above calls the /wp-json/wp/v2/posts API and returns WordPress Posts. Invoke-RestMethod -method get -uri " -headers $header $userPassword = 'ABCD wTUZ pIST 9jEo 99LV 1234' Update $userID for your WordPress User Account Alias, the $userPassword with the Application Password generated above and in the Invoke-RestMethod API query update the URL for your WordPress site. The snippet below shows how to use the Application Password generated above for your WordPress Account with Basic Authentication to call v2 WordPress APIs. Record the generated password for use in your PowerShell automation script. This is just a friendly display-name in the console. It does not matter what you name the Application Password. From your WordPress Admin Console select Users => Your User Account => Add New Application Password. To access the v2 WordPress API’s you will first need to configure your WordPress User Account Profile with an Application Password. For completeness and to document it for any future requirements I may have, this post will detail authenticating and querying both the v1.1 and v2 APIs. This does also impact how authentication is performed. My blog is hosted by a hosting provider, and I authenticate directly to my WordPress environment. Also, the two APIs differed in their implementations for authentication and use. Reading through the documentation for each it became apparent that only the v1.1 API had an endpoint that would return views and visitor statistics. What I was trying to achieve was to automate the process of retrieving statistics on views and visitors to my blog.Īfter some investigation I learned that there are two separate APIs for WordPress. Anyway, that’s rather irrelevant for this post which about accessing WordPress APIs with PowerShell. Why WordPress? Well, it was the most prevalent platform when I started this blog back in 2016 and it was more powerful and extensible than Blogger which I had used previously.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |