Discussion Accessing the API using Curl

I have been playing around with the API from the command line so thought I'd put down my notes as a quick-start guide to accessing the API.

The first step that you will need to carry out is to login. To do so you can use the following command:

Code:
EMAIL=YOUR_LOGIN_EMAIL_HERE
PASSWORD=YOUR_PASSWORD_HERE
USER_AGENT="Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257"
curl -c cookies.txt -H "User-Agent: ${USER_AGENT}" -d email=${EMAIL} -d password="${PASSWORD}" https://companion.orerve.net/user/login

If the email and password are correct you should receive an authentication token to the email account specified in ${EMAIL}, the same as you would when you first log in to a machine. Note that if you have any special characters in your password (e.g. &) then these will need to be escaped using standard URL encoding.

Once you have this code you can send the confirmation request:

Code:
CODE=YOUR_CONFIRMATION_CODE_HERE
curl -b cookies.txt -c cookies.txt -H "User-Agent: ${USER_AGENT}" -d code=${CODE} https://companion.orerve.net/user/confirm

Again assuming that the code is correct you will now be set up to request data using the API. For example to obtain your profile:

Code:
curl -b cookies.txt -c cookies.txt -H "User-Agent: ${USER_AGENT}" https://companion.orerve.net/profile | sed -e 's/True/true/g' -e 's/False/false/g' -e s/\'/\"/g

The munging of the returned data via sed is to turn it in to standard JSON; feel free to skip this bit if you have a more forgiving parser.
 
Last edited:

wolverine2710

Tutorial & Guide Writer
Wow! Nice to get all this from a tiny command line, very nice.

Its a real GEM. Curl is tiny but extremely powerfull. There is also libcurl - the multiprotocol file transfer library. It has support for over 40 languages. Both are open source. Its amazing what you can do with both. Ideal for usage in tools. Both are higly portable and ported to almost every Operating System and programming language out there.

Curl info in the spoiler tag
curl is an open source command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more.
What's curl used for?
curl is used in command lines or scripts to transfer data. It is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players and is the internet transfer backbone for thousands of software applications totally affecting more than one billion users.
Who makes curl?
curl is free and open software that compiles and runs under a wide variety of operating systems. curl exists thanks to thousands of contributors.
What's the latest curl?
The most recent stable version is 7.46.0, released on 2nd of December 2015. Currently, 112 of the listed downloads are of the latest version.
Where's the code?
Check out the latest source code from github.

Libcurl info in the spoiler tag.
libcurl - the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more!
libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...
libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies and numerous applications.
Download
Go to the regular curl download page and get the latest curl package, or one of the specific libcurl packages listed.
API
You use libcurl with the provided C API or one of the over 40 available bindings. The cURL team works hard to keep the API and ABI stable.
Howto
Check out our using libcurl page for general hints and advice, the free HTTP client library comparison. or read the comparisons against libwww and WinInet.
libcurl is most probably the most portable, most powerful and most often used C-based multi-platform file transfer library on this planet - be it open source or commercial.
 
Last edited:

wolverine2710

Tutorial & Guide Writer
@jgm. Thanks so much for sharing this with us. Rep +1. Its great to see that now that the usage of the iPhone api is LEGAL commanders are sharing their knowledge and proof of concepts with the community.

I've taken the liberty to create an EDCodex entry for it: "Accessing the iPhone companion app api using curl". It would be great if you could take over the entry and enhance my humble attempt. I've added some admin comment about usage with other Operating Sytems and mentioned libCurl. Just register for EDCodex and send biobob or myself a PM with the email address used for the registration. You then become the owner of the entry and can edit it as you see fit.

It would be superb if this Unix example could be ported to a window .bat file and to the MS powershell. Perhaps you or someone else could do that.

Update: I've mentioned your thread in the EDDN thread. You can find it here.
 
Last edited:
I realize that I'm super late to this but I still wanted to add my thanks! cURL examples are the best way to explain how to use a web (and particularly REST) APIs.
 
Back
Top Bottom