Hi,
I am trying to work out how to PUT a command to a URL.
I am using a nonUI app.
So far I have:
This will return:
ResponseError. Reason: Unauthorized, Response: {"errorMessage":"Invalid credentials","errorCode":"10000001"}
Based on the documentation it looks like my username and password wasn't accepted but I know I am differently using the correct username and password.
The documentation explains how to do it in Node.js:
curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Basic QWFyb25xxxxxxxxxxxxxx1YzZkYw==" -d "{
\"status\": \"DEACTIVATED\"
}" "https://restapi.URL.HERE"
I am guessing there is something wrong with my B4J code ?
I am trying to work out how to PUT a command to a URL.
I am using a nonUI app.
So far I have:
B4X:
Sub AppStart (Args() As String)
Run
StartMessageLoop
End Sub
Private Sub Run
Dim job1 As HttpJob ' Lib jOKHttpUtils2_NONUI v2.62
Dim URL As String = "https://restapi.URL.HERE"
Dim userName As String = "MyUsername"
Dim password As String = "MyPassword"
Dim MyString As String
MyString = $"{
"status": "DEACTIVATED"
}"$
job1.Initialize("JOB1", Me)
job1.Username = userName
job1.Password = password
job1.PutString(URL,MyString)
Wait for JobDone (Job As HttpJob)
If Job.Success = True Then
Log(Job.GetString)
End If
Job.Release
End Sub
This will return:
ResponseError. Reason: Unauthorized, Response: {"errorMessage":"Invalid credentials","errorCode":"10000001"}
Based on the documentation it looks like my username and password wasn't accepted but I know I am differently using the correct username and password.
The documentation explains how to do it in Node.js:
B4X:
var request = require('request');
var body = [];
var auth = "Basic " + new Buffer("username:password").toString("base64");
request({
method: 'PUT',
url: 'https://restapi.URL.HERE',
headers : {"Authorization" : auth},
body: {"status":"DEACTIVATED"},
json: true
},
function (error, response, body) {
if(error) {
console.log('Error:', error);
return;
} else {
// return statusCode
console.log(response.statusCode);
// return contentType
console.log(response.headers['content-type']);
console.log(body);
}
}
)
curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Basic QWFyb25xxxxxxxxxxxxxx1YzZkYw==" -d "{
\"status\": \"DEACTIVATED\"
}" "https://restapi.URL.HERE"
I am guessing there is something wrong with my B4J code ?