curl in LiveCode

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

curl in LiveCode

Paul Dupuis via use-livecode
An API that I use was sunset on 2020-02-01 so I need to convert my  
previous stack calls from their v1 to v2 format. The original method  
was a simple url post but the updated method uses GET via curl. I was  
able to convert my calls to the new format, and can successfully get  
data when using curl through Terminal, but can't figure out how to  
properly curl in LiveCode.

There are several old posts (mailing list and forum) that explain how  
to setup httpHeaders then POST or PUT using libURL, but I can't seem  
to find a GET option. Running a shell command works, but I'd prefer a  
method that ports to mobile if possible. I tried a couple tsNet  
commands, but keep getting assorted 4xx response codes...
tsNetGet - 422
tsNetCustom - 400
tsNetPost - 405

Can anyone explain how to issue this curl command through tsNet or  
libURL and read the JSON that is returned?
curl -G --header  
"Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" --header Accept:=application/json --data ipAddress=172.217.9.174  
https://api.abuseipdb.com/api/v2/check

That is a working API key that I'm willing to throw away now that is public.
v1 of API is @ https://www.abuseipdb.com/api
v2 of API is @ https://docs.abuseipdb.com/

--Andrew Bell


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: curl in LiveCode

Paul Dupuis via use-livecode
Hi,

i just did a short test

this works so far
put "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" into pHeaders
put tsNetGetSync("https://api.abuseipdb.com/api/v2/check?ipAddress=172.217.9.174", pHeaders, rOutHeaders, rResult, rBytes) into tResult

tResult contains the same value as  the one returned executing curl via shell.

The only thing i don´t know is where and how to add the Accept:=application/json




-
Matthias Rebbe
Life Is Too Short For Boring Code

> Am 13.02.2020 um 22:27 schrieb Andrew Bell via use-livecode <[hidden email]>:
>
> An API that I use was sunset on 2020-02-01 so I need to convert my previous stack calls from their v1 to v2 format. The original method was a simple url post but the updated method uses GET via curl. I was able to convert my calls to the new format, and can successfully get data when using curl through Terminal, but can't figure out how to properly curl in LiveCode.
>
> There are several old posts (mailing list and forum) that explain how to setup httpHeaders then POST or PUT using libURL, but I can't seem to find a GET option. Running a shell command works, but I'd prefer a method that ports to mobile if possible. I tried a couple tsNet commands, but keep getting assorted 4xx response codes...
> tsNetGet - 422
> tsNetCustom - 400
> tsNetPost - 405
>
> Can anyone explain how to issue this curl command through tsNet or libURL and read the JSON that is returned?
> curl -G --header "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" --header Accept:=application/json --data ipAddress=172.217.9.174 https://api.abuseipdb.com/api/v2/check
>
> That is a working API key that I'm willing to throw away now that is public.
> v1 of API is @ https://www.abuseipdb.com/api
> v2 of API is @ https://docs.abuseipdb.com/
>
> --Andrew Bell
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: curl in LiveCode

Paul Dupuis via use-livecode
Hi again,
rereading my post i noticed that the Accept...   is also a header.
So this a modified version of my sample script

-- build header

put "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" into pHeaders -- api key

put return & "Accept:=application/json" after pHeaders -- request JSON

-- now build url with parameters
put "https://api.abuseipdb.com/api/v2/check" into pURL

put "?ipAddress=172.217.9.174" after pURL -- add ip address

put "&maxAgeInDays=90" after pUrl -- this is just to show how additional parameters are added to the url

put "&verbose" after pURL -- this is just to show how additional parameters are added to the url

-- now get the data
put tsNetGetSync(pURL, pHeaders, rOutHeaders, rResult, rBytes) into tResult

put rOutHeaders after message -- show the received headers in message box


-
Matthias Rebbe
Life Is Too Short For Boring Code

> Am 13.02.2020 um 22:45 schrieb matthias rebbe via use-livecode <[hidden email]>:
>
> Hi,
>
> i just did a short test
>
> this works so far
> put "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" into pHeaders
> put tsNetGetSync("https://api.abuseipdb.com/api/v2/check?ipAddress=172.217.9.174", pHeaders, rOutHeaders, rResult, rBytes) into tResult
>
> tResult contains the same value as  the one returned executing curl via shell.
>
> The only thing i don´t know is where and how to add the Accept:=application/json
>
>
>
>
> -
> Matthias Rebbe
> Life Is Too Short For Boring Code
>
>> Am 13.02.2020 um 22:27 schrieb Andrew Bell via use-livecode <[hidden email]>:
>>
>> An API that I use was sunset on 2020-02-01 so I need to convert my previous stack calls from their v1 to v2 format. The original method was a simple url post but the updated method uses GET via curl. I was able to convert my calls to the new format, and can successfully get data when using curl through Terminal, but can't figure out how to properly curl in LiveCode.
>>
>> There are several old posts (mailing list and forum) that explain how to setup httpHeaders then POST or PUT using libURL, but I can't seem to find a GET option. Running a shell command works, but I'd prefer a method that ports to mobile if possible. I tried a couple tsNet commands, but keep getting assorted 4xx response codes...
>> tsNetGet - 422
>> tsNetCustom - 400
>> tsNetPost - 405
>>
>> Can anyone explain how to issue this curl command through tsNet or libURL and read the JSON that is returned?
>> curl -G --header "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" --header Accept:=application/json --data ipAddress=172.217.9.174 https://api.abuseipdb.com/api/v2/check
>>
>> That is a working API key that I'm willing to throw away now that is public.
>> v1 of API is @ https://www.abuseipdb.com/api
>> v2 of API is @ https://docs.abuseipdb.com/
>>
>> --Andrew Bell
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: curl in LiveCode

Paul Dupuis via use-livecode
In reply to this post by Paul Dupuis via use-livecode
Thank you Matthias! I figured it was possible and I might be close.  
Hopefully the archive of this thread will be useful for someone in the  
future.

--Andrew Bell

> Subject: Re: curl in LiveCode
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=utf-8
>
> Hi again,
> rereading my post i noticed that the Accept...   is also a header.
> So this a modified version of my sample script
>
> -- build header
>
> put  
> "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" into pHeaders -- api  
> key
>
> put return & "Accept:=application/json" after pHeaders -- request JSON
>
> -- now build url with parameters
> put "https://api.abuseipdb.com/api/v2/check" into pURL
>
> put "?ipAddress=172.217.9.174" after pURL -- add ip address
>
> put "&maxAgeInDays=90" after pUrl -- this is just to show how  
> additional parameters are added to the url
>
> put "&verbose" after pURL -- this is just to show how additional  
> parameters are added to the url
>
> -- now get the data
> put tsNetGetSync(pURL, pHeaders, rOutHeaders, rResult, rBytes) into tResult
>
> put rOutHeaders after message -- show the received headers in message box
>
>
> -
> Matthias Rebbe
> Life Is Too Short For Boring Code
>
>> Am 13.02.2020 um 22:45 schrieb matthias rebbe via use-livecode  
>> <[hidden email]>:
>>
>> Hi,
>>
>> i just did a short test
>>
>> this works so far
>> put  
>> "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" into  
>> pHeaders
>> put  
>> tsNetGetSync("https://api.abuseipdb.com/api/v2/check?ipAddress=172.217.9.174", pHeaders, rOutHeaders, rResult, rBytes) into  
>> tResult
>>
>> tResult contains the same value as  the one returned executing curl  
>> via shell.
>>
>> The only thing i don?t know is where and how to add the  
>> Accept:=application/json
>>
>>
>>
>>
>> -
>> Matthias Rebbe
>> Life Is Too Short For Boring Code
>>
>>> Am 13.02.2020 um 22:27 schrieb Andrew Bell via use-livecode  
>>> <[hidden email]>:
>>>
>>> An API that I use was sunset on 2020-02-01 so I need to convert my  
>>> previous stack calls from their v1 to v2 format. The original  
>>> method was a simple url post but the updated method uses GET via  
>>> curl. I was able to convert my calls to the new format, and can  
>>> successfully get data when using curl through Terminal, but can't  
>>> figure out how to properly curl in LiveCode.
>>>
>>> There are several old posts (mailing list and forum) that explain  
>>> how to setup httpHeaders then POST or PUT using libURL, but I  
>>> can't seem to find a GET option. Running a shell command works,  
>>> but I'd prefer a method that ports to mobile if possible. I tried  
>>> a couple tsNet commands, but keep getting assorted 4xx response  
>>> codes...
>>> tsNetGet - 422
>>> tsNetCustom - 400
>>> tsNetPost - 405
>>>
>>> Can anyone explain how to issue this curl command through tsNet or  
>>> libURL and read the JSON that is returned?
>>> curl -G --header  
>>> "Key:e9242121ffd235b16f06c6e09cfd4373d18aa85d77dab4b858601051d4dd5b914ec298a3a29520ab" --header Accept:=application/json --data ipAddress=172.217.9.174  
>>> https://api.abuseipdb.com/api/v2/check
>>>
>>> That is a working API key that I'm willing to throw away now that  
>>> is public.
>>> v1 of API is @ https://www.abuseipdb.com/api
>>> v2 of API is @ https://docs.abuseipdb.com/
>>>
>>> --Andrew Bell
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your  
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>> ________________________




_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode