Jump to content

Can someone please show me how to use cURL and Autoit


Recommended Posts

Guys,

     I've read that I can use Autoit and cURL together. I'm familiar with autoit but not with cURL and command line stuff. Is there anyone here that can help? I tried using> cURL udf but I keep getting errors and I made a post on that string a few weeks ago but no answers. So I found another string using cURL but I don't know how to use it.

This is what I have so far

Dim $iPidCurl = Run(@ComSpec & " /c " & 'curl -i -H' & 'Content-Type: application/x-www-form-urlencoded' & 'https://api.edmunds.com/inventory/token' & '-X POST -d ' & 'client_id=<MY SECRET ID >'&' -d ' & 'client_secret=<MY SECRET PHRASE>' & ' -d ' &'grant_type=client_credentials', @ScriptDir, @SW_HIDE,2+4)

Dim $sOut
While 1
    $sOut &= StdoutRead($iPidCurl)
    If @error Then ExitLoop
WEnd
While 1
    $sOut &= StderrRead($iPidCurl)
    If @error Then ExitLoop
WEnd
ConsoleWrite($sOut&@LF&"*********"&@LF)

This is where I'm trying to use it and they show what needs to be sent I think.

http://developer.edmunds.com/api-documentation/inventory/

The first section "OAUTH 2.0"

 

Link to comment
Share on other sites

Something like this would be closer..

Dim $iPidCurl = Run('curl.exe -i -H Content-Type: application/x-www-form-urlencoded -X POST -d client_id=MYSECRETID&client_secret=<MYSECRETPHRASE>&grant_type=client_credentials  https://api.edmunds.com/inventory/token ', @ScriptDir, @SW_HIDE,2+4)

 

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

Thanks Corz for your reply. I just tried your suggestion and I did get a response back. I don't know what it means though. Some type of certificate problem.

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: application

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

*********
Link to comment
Share on other sites

just updated my version of cURL and I'm getting a different response.

HTTP/1.1 401 Unauthorized
Cache-Control: no-store
Content-Type: application/json;charset=UTF-8
Date: Tue, 08 Jul 2014 21:14:47 GMT
Server: Mashery Proxy
WWW-Authenticate: Basic realm="api.edmunds.com"
X-Mashery-Error-Code: ERR_403_DEVELOPER_INACTIVE
X-Mashery-Responder: prod-j-worker-us-east-1c-34.mashery.com
Content-Length: 26
Connection: keep-alive

{"error":"invalid_client"}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: application

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   133  100    26  100   107     63    262 --:--:-- --:--:-- --:--:--   262
Link to comment
Share on other sites

The response I'm getting is weird. I have access to the API, I can login manually and get an access token. Does anyone have any pointers on what I'm doing wrong?? I'm using Corz's syntax and the recent version of CURL for windows.

Link to comment
Share on other sites

Is there any helpdesk at the site you are connecting to?  If so, request a C#, or curl sample, and modify it for your params.

Otherwise, this seems more like a google question, or stack overflow...you have already worked out the autoit piece, which performs the execution.

I'd suggest you keep playing with the params via a command prompt, so you get quicker returns, and when it's ironed out, then port it over to an au3 file.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Yup, what he said!

I'm no great cURL expert, I was just fixing what was an obviously broken command-line!

Having said that, I don't think I've never needed to use  Content-Type: application/x-www-form-urlencoded, Isn't that implicit with " -X POST"?

I notice it's a JSON response. Do you not also have to send JSON data ("Content-Type: application/json")?

Anyways, like jdelaney says, play around with it in the terminal until it works, then create the AutoIt code, which will be a simple copy/paste.

;o) Cor

Edited by corz

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

The response I'm getting is weird. I have access to the API, I can login manually and get an access token. Does anyone have any pointers on what I'm doing wrong?? I'm using Corz's syntax and the recent version of CURL for windows.

 

The Inventory API is available only to API Partners and Edmunds Developers. Which one are you?

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thank you guys for your replys. I think I'm set up as a developer. I can access everything with in the api. I'm currently working on a web application and I need to get a new access token once the old one expires. The tokens expire every hour.  I can login manually and get a new token on the fly for testing purposes. That's not a problem. Below is what is stated on their API support website.

The Inventory API requires OAuth 2.0 for both authentication and authorization. Here is how you would get an OAuth access token:

    curl -i -H 'Content-Type: application/x-www-form-urlencoded' 'https://api.edmunds.com/inventory/token' -X POST -d 'client_id=<api key>' -d 'client_secret=<shared secret>' -d 'grant_type=client_credentials'

I have the api key and the secret phrase. It works.

I don't know anything about or have ever used curl. I didn't know what it was until a few days ago.  I was told that this is how to request a new token. To test the api, Once I'm logged in, I can request a new token on the fly.

Link to comment
Share on other sites

Woooooo Hooooooo.....  Praise Jesus.... I just got this thing working :thumbsup:  LOL

I had to flip all the param's around and remove the < >'s in the id and secret phrase. There was a space in the "Content-Type: application" example on the website. I removed that to. Put some "&" signs between the client id, secret and grant type and ran it  and BOOM, there's my token.

 

Thank you, thank you, thank you guys and girl for your help.

Link to comment
Share on other sites

trance,

      I would love, love, love to use the WinHttp UDF. I've had it downloaded for quite some time now and tried using it prior to this on other projects but I didn't have any success. I simply don't know how to use it. I could use it in so many of my other scripts I'm running.  I think I sent you a PM with questions. I can't remember. I'm gonna crack it open again and try it  with this project.

 

Once again, thank you guys so much for your help and advice. It's truly appreciated :)

Link to comment
Share on other sites

I may not read your PM. If it's exams time then very likely that's the case.

Did you have troubles with the help file WinHttp.au3 comes with?

I'm not sure if you're able to see this message in full, I can't really post on this forum freely since today. But anyway, what's the exact code that works for you using curl (just post it with wrong api key and secret) and I'll try to write WinHttp version to test.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Wow! Thank you so much Trancexx.

Here's exactly what I used with changed credentials.

$url = "curl.exe -i -H Content-Type:application/x-www-form-urlencoded https://api.edmunds.com/inventory/token -X POST -d client_id=ABC123&client_secret=ABC123&grant_type=client_credentials"

Dim $iPidCurl = Run($url, @ScriptDir, @SW_HIDE,2+4)
Dim $sOut
While 1
    $sOut &= StdoutRead($iPidCurl)
    If @error Then ExitLoop
WEnd
While 1
    $sOut &= StderrRead($iPidCurl)
    If @error Then ExitLoop
WEnd
ConsoleWrite($sOut&@LF&"*********"&@LF)
Link to comment
Share on other sites

This is what it is returning. I changed token and mapi

HTTP/1.1 200 OK
Cache-Control: no-store
Content-Type: application/json;charset=UTF-8
Date: Thu, 10 Jul 2014 22:47:11 GMT
Server: Mashery Proxy
X-Mashery-Responder: prod-j-worker-us-east-1d-38.mashery.com
Content-Length: 117
Connection: keep-alive

{"token_type":"bearer","mapi":"abc123","access_token":"abc123","expires_in":3600}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   220  100   117  100   103    267    235 --:--:-- --:--:-- --:--:--   267

Here's a link on the main website that explains what should return.

http://developer.edmunds.com/api-documentation/inventory/vehicle_listings/v1/01_listings_by_dealer/api-description.html

Right now, once I get the token, I build the URL and use _InetGetSource to return the data I need.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...