API Request Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
G_Allen

API Request

07 Aug 2017, 22:32

I have the API Key and the following URL: http://www.carrierlookup.com/index.php/ ... p?key={api key}&number={phone numbe

Returns JSON encoded object. creditBalance value gives current credits on the account. number is the phone number that was requested. carrier_type is whether the number is a landline or mobile. carrier is valid if carrier_type is mobile -- it will return the cell phone provider.

I am very new to HTTPRequest so I am missing something. I get a null message in the MsgBox.
I need to return the values for creditBalance, carrier_type and the cell phone Provider.

Here is the API Call code I have tried.
Token := "2971615f5ffdeb2dd2395ef34b6adc10e3f84abc"
EndPoint := "http://www.carrierlookup.com/index.php/api/lookup?key=" . Token
Type := "lookup"
Format := "JSON"
Full_URL := "http://www.carrierlookup.com/index.php/api/lookup?key=" . Token
Status := HTTP.Status
;***********************************************

HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("POST", Full_URL)
HTTP.SetRequestHeader("Accept", "*/*")
HTTP.SetRequestHeader("Accept-Language","en-US")
HTTP.SetRequestHeader("Content-Type", "application/x-www.form-urlencoded")
HTTP.Send(phonenumber)
HTTP.Status
;~ msgbox % http.GetAllResponseHeaders()
JSON_Data :=http.ResponseText
MsgBox % Status
MsgBox % JSON_Data
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: API Request

08 Aug 2017, 02:54

Are you sure your "Full_URL" is working? when I paste http://www.carrierlookup.com/index.php/ ... 10e3f84abc in my browser I get "null" as an answer
G_Allen

Re: API Request

08 Aug 2017, 10:07

That is my problem, I also get null as a response. I checked the key and it works in the other GET call that I have.
The URL is from what they sent me that I posted at the top of my previous post.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: API Request

08 Aug 2017, 12:55

But then it is not your script but the url that's the problem. Maybe you need to be inside a firewall or something to get to work?
G_Allen

Re: API Request

16 Aug 2017, 13:14

I checked with the developer at the site of the API. He says that apparently the number is not being sent.
He sent me the following, which works in a browser.
http://www.carrierlookup.com/index.php/ ... 4178613971

I am not seeing how to make this work in the WinHTTPRequest
G_Allen

WinHTTPRequest Post not working  Topic is solved

16 Aug 2017, 13:30

I have the following URL for API request from the web site that works in a browser.

http://www.carrierlookup.com/index.php/ ... 4178613971

The autohotkey script I have tried is:

api_key := "2971615f5ffdeb2dd2395ef34b6adc10e3f84abc"
EndPoint := "http://www.carrierlookup.com/index.php/api/lookup?key=" . Token
Type := "lookup"
Format := "JSON"
Full_URL := "http://www.carrierlookup.com/index.php/api/lookup?key=" . Token
;Status := HTTP.Status
;***********************************************
;~http://www.carrierlookup.com/index.php/ ... 4178613971
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("POST", Full_URL)
HTTP.SetRequestHeader("Accept", "*/*")
HTTP.SetRequestHeader("Accept-Language","en-US")
HTTP.SetRequestHeader("Content-Type", "application/x-www.form-urlencoded")
HTTP.Send(4178613971)
HTTP.Status
JSON_Data :=http.ResponseText
msgbox % "status: " status "`n`nresult: " result

The developer at the site tells me the number is not being sent.
How do I fix this?
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: API Request

16 Aug 2017, 15:04

your not setting the value of Token
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: API Request

16 Aug 2017, 15:06

your also doing a POST with the number and no key. try putting it all in the URL and doing GET
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Guest

Re: API Request

18 Aug 2017, 12:14

This is what we ended up with that works.
Thanks everyone!

Code: Select all

url = http://www.carrierlookup.com/index.php/api/lookup
trackOrder_url = http://www.carrierlookup.com/index.php/api/lookup?key=2971615f5ffdeb2dd2395ef34b6adc10e3f84abc&number=
Number= 4178613971
FileDelete, test.html

WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      WebRequest.Open("GET", url, false)
      WebRequest.Send()
                  WebRequest.Open("POST", trackOrder_url . Number, false)
                  WebRequest.Send()
                  contents := WebRequest.ResponseText
      FileAppend, %contents%, test.html
                  run test.html
                  

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, RussF and 399 guests