API HTTP Method POST in AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

API HTTP Method POST in AHK

Post by armin889 » 05 Nov 2022, 09:09

Hello, autohotkey Community

Is it possible to send with HTTP Method POST in AHK to this api to Add Order
Nvt8tYACi5.jpg
Nvt8tYACi5.jpg (53.31 KiB) Viewed 1478 times
Thanks a lot of guys

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: API HTTP Method POST in AHK

Post by teadrinker » 05 Nov 2022, 16:52

Do you have API Key? Do you know Service ID?

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: API HTTP Method POST in AHK

Post by armin889 » 06 Nov 2022, 03:02

Hello teadrinker I am happy to read your answer :wave:

sure, I have api-key
Spoiler
Service ID is just a number between 1 and 34 for test u can use 13

Thanks for try to help me

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: API HTTP Method POST in AHK

Post by teadrinker » 06 Nov 2022, 13:06

The request should look like this:

Code: Select all

key := "your api key"
action := "add"
service := 13
link := "https://link"
quantity := 1
cpc := 1

url := "https://www.like4like.org/api/v1/" . "?key=" . key
                                           . "&action=" . action
                                           . "&service=" . service
                                           . "&link=" . EncodeDecodeURI(link)
                                           . "&quantity=" . quantity
                                           . "&cpc=" . cpc

json := WebRequest(url, "POST",,, error := "")
if error
   MsgBox, Error: %error%
MsgBox, Response:`n%json%

WebRequest(url, method := "GET", HeadersArray := "", body := "", ByRef error := "") {
   Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   Whr.Open(method, url, true)
   for name, value in HeadersArray
      Whr.SetRequestHeader(name, value)
   Whr.Send(body)
   Whr.WaitForResponse()
   status := Whr.status
   if (status != 200)
      error := "HttpRequest error, status: " . status
   Arr := Whr.responseBody
   pData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)
   length := Arr.MaxIndex() + 1
   Return StrGet(pData, length, "UTF-8")
}

EncodeDecodeURI(str, encode := true, component := true) {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate("htmlfile")
      Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
      JS := Doc.parentWindow
      ( Doc.documentMode < 9 && JS.execScript() )
   }
   Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
Can't test it since I don't know the rest of parameters.

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: API HTTP Method POST in AHK

Post by armin889 » 06 Nov 2022, 14:35

First, thanks a lot for your work. Your script looks amazing :bravo:

Well, I get the Error "missing action"
I am not sure what's wrong. Tried some things, could not figure it out .

This is a working example script for php, maybe it helps to find the problem:

Code: Select all

<?PHP
class API
{

    public $api_url = 'https://www.like4like.org/api/v1/'; // API URL

    public $api_key = ''; // Your API key

    public function order($data) { // add order
        $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
        return json_decode($this->connect($post));
    }

    public function status($data) { // get order status
        $post = array_merge(array('key' => $this->api_key, 'action' => 'status'), $data);
        return json_decode($this->connect($post));
    }

    public function balance() { // get balance
        return json_decode($this->connect(array(
            'key' => $this->api_key,
            'action' => 'balance',
        )));
    }

    private function connect($post) {
        $_post = Array();
        if (is_array($post)) {
            foreach ($post as $name => $value) {
                if ($name == 'link') {
                    $_post[] = $name.'='.urlencode(str_replace('&', '9ampersand9', $value));
                } else {
                    $_post[] = $name.'='.urlencode($value);
                }
            }
        }

        $ch = curl_init($this->api_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        if (is_array($post)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
        }
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        $result = curl_exec($ch);
        if (curl_errno($ch) != 0 && empty($result)) {
            $result = false;
        }
        curl_close($ch);
        return $result;
    }
}

// Examples

$api = new API();

$balance = $api->balance(); 
# return user Free Credits and Bought Credits

$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'cpc' => 3)); 
#service = ID Service from the Service list
#link = URL you want to insert 
#quantity = count of likes/follows you want to get on inserted URL
#cpc = from 2 to 21 credits - Cost per click (like/follow)

$status = $api->status(array('service' => 1, 'order' => 15869)); 
#service = ID Service from the Service list
#order = result from order function $order->order

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: API HTTP Method POST in AHK

Post by teadrinker » 06 Nov 2022, 23:24

Try this:

Code: Select all

key := "your api key"
action := "add"
service := 13
link := "https://link"
quantity := 1
cpc := 1

url := "https://www.like4like.org/api/v1/"

body := "key=" . key
      . "&action=" . action
      . "&service=" . service
      . "&link=" . EncodeDecodeURI(link)
      . "&quantity=" . quantity
      . "&cpc=" . cpc
                    
json := WebRequest(url, "POST", {"Content-Type": "application/x-www-form-urlencoded"}, body, error := "")
if error
   MsgBox, Error: %error%
MsgBox, Response:`n%json%

WebRequest(url, method := "GET", HeadersArray := "", body := "", ByRef error := "") {
   Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   Whr.Open(method, url, true)
   for name, value in HeadersArray
      Whr.SetRequestHeader(name, value)
   Whr.Send(body)
   Whr.WaitForResponse()
   status := Whr.status
   if (status != 200)
      error := "HttpRequest error, status: " . status
   Arr := Whr.responseBody
   pData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)
   length := Arr.MaxIndex() + 1
   Return StrGet(pData, length, "UTF-8")
}

EncodeDecodeURI(str, encode := true, component := true) {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate("htmlfile")
      Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
      JS := Doc.parentWindow
      ( Doc.documentMode < 9 && JS.execScript() )
   }
   Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: API HTTP Method POST in AHK

Post by armin889 » 07 Nov 2022, 04:57

Amazing it work :bravo:
I tested it, works every time

my last question, I get this respawn from script
AutoHotkey_9TEYSgFFUO.jpg
AutoHotkey_9TEYSgFFUO.jpg (8.41 KiB) Viewed 1267 times
How I can save, 791591 to a variable?

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: API HTTP Method POST in AHK

Post by teadrinker » 07 Nov 2022, 09:37

Code: Select all

json = {"order":791591,"service":19}
RegExMatch(json, """order"":\K\d+", order)
MsgBox, % order

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: API HTTP Method POST in AHK

Post by armin889 » 07 Nov 2022, 10:59

Thanks.
The msgbox got back empty
Well after lot of testing i found the problem, in response "791591" is in ""

Code: Select all

json = {"order":"791591","service":19}
your code is for 791591 without ""
teadrinker wrote:
07 Nov 2022, 09:37

Code: Select all

json = {"order":791591,"service":19}
RegExMatch(json, """order"":\K\d+", order)
MsgBox, % order

maybe you know how to fix this in RegExMatch

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: API HTTP Method POST in AHK  Topic is solved

Post by teadrinker » 07 Nov 2022, 12:04

Ah, sorry. :)

Code: Select all

json = {"order":"791591","service":19}
RegExMatch(json, """order"":""\K\d+", order)
MsgBox, % order

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: API HTTP Method POST in AHK

Post by armin889 » 14 Nov 2022, 17:57

Thanks a lot teadrinker, for your help and support

Post Reply

Return to “Ask for Help (v1)”