Using cURL

cURL

You can easily interact with the M2X API using cURL, a powerful command-line tool for making HTTP calls. Once you learn how to use cURL, the M2X Command-Line Cheatsheet will provide you with specific cURL commands that you'll need to begin pushing data into M2X.

Pre-requisites: Windows 7 or later, or Mac OS X 10.7 or later (for this guide) cURL itself works with almost any OS. You can find a full list here: http://curl.haxx.se/docs/install.html.

Downloading + installing cURL on Windows

Note: (cURL is already installed on Mac computers)

Use the following steps to install cURL:

  1. 1Open http://curl.haxx.se/dlwiz?type=bin in a browser.
  2. 2Select your operating system in the dropdown box: either Windows /Win32 or Win 64. Click Select!
  3. 3For Win 32, choose whether you will use cURL in a Windows Command Prompt (Generic) or in a Cygwin terminal (cygwin). For Win 64, choose whether you will use cURL in a Windows Command Prompt (Generic) or MinGW (MinGW64). Click Select!
  4. 4If required, choose your Windows operating system. Finish.
  5. 5Click Download for the version which has SSL enabled.
  6. 6Choose a version with support for SSL.
  7. 7Open the downloaded zip file. Extract the files to an easy-to-find place, such as C:\Program Files.

Testing cURL on Windows

  1. 1Open up the Windows Command Prompt terminal. (From the Start menu, click Run, then type cmd.)
  2. 2 Set the path to include the directory where you put curl.exe. For example, if you put it in C:\Program Files\curl, then you would type the following command:
    $ set path=%path%;"c:\Program Files\curl"
  3. 3 Type curl. You should see the following message:
    $ curl: try 'curl –help' or 'curl –message' for more information
    This means that cURL is installed and the path is correct.
  4. 4 Type:
    $ curl https://api-m2x.att.com/v2
    You should see JSON returned:
    {
    "message":"You must provide a valid API key in the X-M2X-KEY header"
    }

Testing cURL on Mac OS X

  1. 1Open up a Terminal Window (Terminal can be launched from Spotlight, the Dock at the bottom of the screen or even the Applications folder)
  2. 2 Type curl. You should see the following message:
    $ curl: try 'curl –help' or 'curl –message' for more information
    This means that cURL is installed and the path is correct.
  3. 3 Type:
    $ curl https://api-m2x.att.com/v2
    You should see JSON returned:
    {
    "message":"You must provide a valid API key in the X-M2X-KEY header"
    }

Troubleshooting

SSL certification error

If you see an SSL certification error, add a -k flag into your curl command.

https not supported error

If you get an error that says, “Protocol http not supported or disabled in libcurl”, then you need a different version of curl. Make sure you have downloaded one that says SSL enabled. If you have downloaded the Win64 version, try the Win32 version instead, even if you are on a 64 bit machine.