API HTTP Method POST in AHK Topic is solved
API HTTP Method POST in AHK
Hello, autohotkey Community
Is it possible to send with HTTP Method POST in AHK to this api to Add Order Thanks a lot of guys
Is it possible to send with HTTP Method POST in AHK to this api to Add Order Thanks a lot of guys
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: API HTTP Method POST in AHK
Do you have API Key? Do you know Service ID?
Re: API HTTP Method POST in AHK
Hello teadrinker I am happy to read your answer
sure, I have api-key
Thanks for try to help me
![Waving :wave:](./images/smilies/icon_wave.gif)
sure, I have api-key
Spoiler
Service ID is just a number between 1 and 34 for test u can use 13Thanks for try to help me
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: API HTTP Method POST in AHK
The request should look like this:
Can't test it since I don't know the rest of parameters.
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)
}
Re: API HTTP Method POST in AHK
First, thanks a lot for your work. Your script looks amazing
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:
![Bravo! :bravo:](./images/smilies/bravo.gif)
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
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: API HTTP Method POST in AHK
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)
}
Re: API HTTP Method POST in AHK
Amazing it work
I tested it, works every time
my last question, I get this respawn from script How I can save, 791591 to a variable?
![Bravo! :bravo:](./images/smilies/bravo.gif)
I tested it, works every time
my last question, I get this respawn from script How I can save, 791591 to a variable?
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: API HTTP Method POST in AHK
Code: Select all
json = {"order":791591,"service":19}
RegExMatch(json, """order"":\K\d+", order)
MsgBox, % order
Re: API HTTP Method POST in AHK
Thanks.
The msgbox got back empty
Well after lot of testing i found the problem, in response "791591" is in ""
your code is for 791591 without ""
maybe you know how to fix this in RegExMatch
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}
teadrinker wrote: ↑07 Nov 2022, 09:37Code: Select all
json = {"order":791591,"service":19} RegExMatch(json, """order"":\K\d+", order) MsgBox, % order
maybe you know how to fix this in RegExMatch
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: API HTTP Method POST in AHK Topic is solved
Ah, sorry.
![Smile :)](./images/smilies/icon_e_smile.gif)
Code: Select all
json = {"order":"791591","service":19}
RegExMatch(json, """order"":""\K\d+", order)
MsgBox, % order
Re: API HTTP Method POST in AHK
Thanks a lot teadrinker, for your help and support