Hi, I am now working on using the WP REST API to confirm login details of my apps user. I`m using the following code, which is partially working; but I`m not getting the expected response from the API.
The code I`m using is
But I`m getting the response :
I have tried changing the username & password and I get a message saying incorrect UN/PW (respectively), so would appear things are too far off.
But I am expecting something like this :
The code I`m using is
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim SU As StringUtils
Dim s As String = "aaaa:bbbb"
Dim e As String = SU.EncodeBase64(s.GetBytes("UTF8"))
Dim j As HttpJob
j.Initialize("log-in", Me)
j.PostString("https://www.ZZZZ.com/wp-json/wp/v2/posts", "")
j.GetRequest.SetHeader("Authorization", "Basic " & e)
Wait For (j) JobDone(job As HttpJob)
If j.Success Then
Log("SUCESS : " & j.GetString)
Else
j.Release
Log("ERROR : " & j.ErrorMessage)
End If
End Sub
But I`m getting the response :
B4X:
ERROR : {"code":"empty_content","message":"Content, title, and excerpt are empty.","data":{"status":400}}
I have tried changing the username & password and I get a message saying incorrect UN/PW (respectively), so would appear things are too far off.
But I am expecting something like this :
B4X:
[
{
"id": 1,
"date": "2023-07-01T01:45:20",
"date_gmt": "2023-07-01T01:45:20",
"guid": {
"rendered": "https://www.ZZZZ.com/?p=1"
},
"modified": "2023-07-01T01:45:20",
"modified_gmt": "2023-07-01T01:45:20",
"slug": "hello-world",
"status": "publish",
"type": "post",
"link": "https://www.ZZZZ.com/2023/07/01/hello-world/",
"title": {
"rendered": "Hello world!"
},
"content": {
"rendered": "\n<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
"protected": false
},
"author": 1,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [
1
],
"tags": [],
"jetpack_featured_media_url": "",
"_links": {
"self": [
{
"href": "https://www.ZZZZ.com/wp-json/wp/v2/posts/1"
}
],
"collection": [
{
"href": "https://www.ZZZZ.com/wp-json/wp/v2/posts"
}
],
"about": [
{
"href": "https://www.ZZZZ.com/wp-json/wp/v2/types/post"
}
],
"author": [
{
"embeddable": true,
"href": "https://www.ZZZZ.com/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"embeddable": true,
"href": "https://www.ZZZZ.com/wp-json/wp/v2/comments?post=1"
}
],
"version-history": [
{
"count": 0,
"href": "https://www.ZZZZ.com/wp-json/wp/v2/posts/1/revisions"
}
],
"wp:attachment": [
{
"href": "https://www.ZZZZ.com/wp-json/wp/v2/media?parent=1"
}
],
"wp:term": [
{
"taxonomy": "category",
"embeddable": true,
"href": "https://www.ZZZZ.com/wp-json/wp/v2/categories?post=1"
},
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "https://www.ZZZZ.com/wp-json/wp/v2/tags?post=1"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]