Sample code for 30+ languages & platforms
AutoIt

WordPress API Key Authentication with miniOrange Plugin

See more WordPress Examples

Demonstrates API key authentication using the miniOrange API Authentication plugin.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

; Use your API key here, such as TaVFjSBu8IMR0MbvZNn7A6P04GXrbtHm
; This causes the "Authorization: Bearer <api_key>" header to be added to each HTTP request.
$oHttp.AuthToken = "api_key"

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1",$oSbResponseBody)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJarrResp = ObjCreate("Chilkat.JsonArray")
$oJarrResp.LoadSb($oSbResponseBody)
$oJarrResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJarrResp.Emit() & @CRLF)

Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oHttp.LastHeader & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)

; [
;   {
;     "id": 1902,
;     "date": "2020-11-16T09:54:09",
;     "date_gmt": "2020-11-16T16:54:09",
;     "guid": {
;       "rendered": "http:\/\/cknotes.com\/?p=1902"
;     },
;     "modified": "2020-11-16T09:54:09",
;     "modified_gmt": "2020-11-16T16:54:09",
;     "slug": "xero-redirect-uri-for-oauth2-and-desktop-apps",
;     "status": "publish",
;     "type": "post",
;     "link": "https:\/\/cknotes.com\/xero-redirect-uri-for-oauth2-and-desktop-apps\/",
;     "title": {
;       "rendered": "Xero Redirect URI for OAuth2 and Desktop Apps"
;     },
;     "content": {
;       "rendered": "<p>...",
;       "protected": false
;     },
;     "excerpt": {
;       "rendered": "<p>...",
;       "protected": false
;     },
;     "author": 1,
;     "featured_media": 0,
;     "comment_status": "closed",
;     "ping_status": "open",
;     "sticky": false,
;     "template": "",
;     "format": "standard",
;     "meta": [
;     ],
;     "categories": [
;       815
;     ],
;     "tags": [
;       594,
;       816
;     ],
;     "_links": {
;       "self": [
;         {
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902"
;         }
;       ],
;       "collection": [
;         {
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts"
;         }
;       ],
;       "about": [
;         {
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post"
;         }
;       ],
;       "author": [
;         {
;           "embeddable": true,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"
;         }
;       ],
;       "replies": [
;         {
;           "embeddable": true,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=1902"
;         }
;       ],
;       "version-history": [
;         {
;           "count": 1,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions"
;         }
;       ],
;       "predecessor-version": [
;         {
;           "id": 1904,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions\/1904"
;         }
;       ],
;       "wp:attachment": [
;         {
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=1902"
;         }
;       ],
;       "wp:term": [
;         {
;           "taxonomy": "category",
;           "embeddable": true,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=1902"
;         },
;         {
;           "taxonomy": "post_tag",
;           "embeddable": true,
;           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=1902"
;         }
;       ],
;       "curies": [
;         {
;           "name": "wp",
;           "href": "https:\/\/api.w.org\/{rel}",
;           "templated": true
;         }
;       ]
;     }
;   },
; ...
; ]

; Sample code for parsing the JSON response...
; Use the following online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON

$oDate_gmt = ObjCreate("Chilkat.DtObj")
Local $oJson
Local $id
Local $sDate
Local $sGuidRendered
Local $sModified
Local $sModified_gmt
Local $slug
Local $status
Local $sV_type
Local $sLink
Local $sTitleRendered
Local $sContentRendered
Local $bContentProtected
Local $sExcerptRendered
Local $bExcerptProtected
Local $iAuthor
Local $iFeatured_media
Local $sComment_status
Local $sPing_status
Local $bSticky
Local $sTemplate
Local $sFormat
Local $iJ
Local $iCount_j
Local $intVal
Local $sHref
Local $bEmbeddable
Local $iCount
Local $sTaxonomy
Local $sName
Local $bTemplated

Local $i = 0
Local $iCount_i = $oJarrResp.Size
While $i < $iCount_i
    $oJson = $oJarrResp.ObjectAt($i)
    $id = $oJson.IntOf("id")
    $sDate = $oJson.StringOf("date")
    $oJson.DtOf("date_gmt",False,$oDate_gmt)
    $sGuidRendered = $oJson.StringOf("guid.rendered")
    $sModified = $oJson.StringOf("modified")
    $sModified_gmt = $oJson.StringOf("modified_gmt")
    $slug = $oJson.StringOf("slug")
    $status = $oJson.StringOf("status")
    $sV_type = $oJson.StringOf("type")
    $sLink = $oJson.StringOf("link")
    $sTitleRendered = $oJson.StringOf("title.rendered")
    $sContentRendered = $oJson.StringOf("content.rendered")
    $bContentProtected = $oJson.BoolOf("content.protected")
    $sExcerptRendered = $oJson.StringOf("excerpt.rendered")
    $bExcerptProtected = $oJson.BoolOf("excerpt.protected")
    $iAuthor = $oJson.IntOf("author")
    $iFeatured_media = $oJson.IntOf("featured_media")
    $sComment_status = $oJson.StringOf("comment_status")
    $sPing_status = $oJson.StringOf("ping_status")
    $bSticky = $oJson.BoolOf("sticky")
    $sTemplate = $oJson.StringOf("template")
    $sFormat = $oJson.StringOf("format")
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("meta")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("categories")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $intVal = $oJson.IntOf("categories[j]")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("tags")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $intVal = $oJson.IntOf("tags[j]")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.self")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sHref = $oJson.StringOf("_links.self[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.collection")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sHref = $oJson.StringOf("_links.collection[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.about")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sHref = $oJson.StringOf("_links.about[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.author")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $bEmbeddable = $oJson.BoolOf("_links.author[j].embeddable")
        $sHref = $oJson.StringOf("_links.author[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.replies")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $bEmbeddable = $oJson.BoolOf("_links.replies[j].embeddable")
        $sHref = $oJson.StringOf("_links.replies[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.version-history")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $iCount = $oJson.IntOf("_links.version-history[j].count")
        $sHref = $oJson.StringOf("_links.version-history[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.predecessor-version")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $id = $oJson.IntOf("_links.predecessor-version[j].id")
        $sHref = $oJson.StringOf("_links.predecessor-version[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.wp:attachment")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sHref = $oJson.StringOf("_links.wp:attachment[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.wp:term")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sTaxonomy = $oJson.StringOf("_links.wp:term[j].taxonomy")
        $bEmbeddable = $oJson.BoolOf("_links.wp:term[j].embeddable")
        $sHref = $oJson.StringOf("_links.wp:term[j].href")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("_links.curies")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $sName = $oJson.StringOf("_links.curies[j].name")
        $sHref = $oJson.StringOf("_links.curies[j].href")
        $bTemplated = $oJson.BoolOf("_links.curies[j].templated")
        $iJ = $iJ + 1
    Wend

    $i = $i + 1
Wend