Rest API Authentication with Autohotkey

i want to POST a string with Autohotkey to a Rest API.

On another question i found something like this:

URL := "http://localhost:8000/createPlayer"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpObj.Open("POST", URL, 0)
HttpObj.SetRequestHeader("Content-Type", "application/json")
json_str := ({"name": "Any Name"})
Body = json_str
HttpObj.Send(Body)
MsgBox, %Body%
Result := HttpObj.ResponseText
Status := HttpObj.Status
msgbox % "status: " status "`n`nresult: " result

so here is my Question: where do i put the authentication-information? I read, that i have tho give the string username:password coded as Base64 to the API, but where? Thank u very much.

The Example in the documentation is(with curl):

curl -u admin:admin -X POST -H 'Content-Type: application/json'
-d'{"type":"page","title":"new page",
"ancestors":[{"id":456}], "space":{"key":"TST"},"body":{"storage":
{"value":
"<p>This is a new page</p>","representation":"storage"}}}'
http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool

my json_string is:

{"type":"page","title":"new page","ancestors":[{"id":13533694}, "space":{"key":"SPIELWIESE"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}

what is wrong?

1 answer

  • answered 2018-04-17 06:28 Garry

    You can send username/password in base64 encoded form as below:

    HttpObj.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );