Help with API Rest (post data)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Noblish
Posts: 28
Joined: 22 Mar 2020, 06:10

Help with API Rest (post data)

Post by Noblish » 07 Oct 2021, 12:42

Hello, I need to Post JSON data to the API, but I'm not sure how to do that, I know how to connect to API and retrieve stuff and work with the data. But posting is something new for me. Any help would be appreciated.

Basically I need to post data to a Thread, the API is from Mirakl. For example... send message to the Operator, or the Client. JSON form. Normally I only need to send the message, but if anyone could explain how I send files, would appreciate too.

Image

cURL request example

Code: Select all

curl --location --request POST 'https://host.com/api/inbox/threads/{THREAD_ID}/message' \
-H "Authorization: {API_KEY}" \
-H "Content-Type: multipart/form-data" \
--form 'message_input={
  "body": "Message body",
  "to": [
    {
      "type": "OPERATOR"
    }
  ]
};type=application/json' \
--form 'files=@/path/to/file.pdf'
My approach:

Code: Select all

ReplyToThread(){
            message_input={"body": "Message body","to": [{"type": "OPERATOR"}]}
            obj := Jxon_Load(message_input)
            URL := "https://" SetMiraklUrl() "/api/inbox/threads/" this.GetID() "/message"
            CreateFormData(postData, hdr_ContentType, obj)
                HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
            HttpObj.Open("POST", URL, true)
            HttpObj.SetRequestHeader("Content-Type", hdr_ContentType)
            HttpObj.SetRequestHeader("Authorization", SetMiraklKey())
            HttpObj.Send(postData)
            HttpObj.WaitForResponse()
                Result := HttpObj.ResponseText
            Status := HttpObj.Status
            If (Status = 201)
                MsgBox, Message Sent
            If (Status != 201)
                msgbox % "status: " status "`n`nresult: " result
        }
I'm using CreateFormData and BinArr. -- https://autohotkey.com/boards/viewtopic.php?f=6&t=7647
Do I need to send the message_input, with Json_Load ?

Noblish
Posts: 28
Joined: 22 Mar 2020, 06:10

Re: Help with API Rest (post data)

Post by Noblish » 08 Oct 2021, 01:33

bump

Post Reply

Return to “Ask for Help (v1)”