
# curl, wget, httpie Geocoding Tutorial

## OpenCage Geocoding API curl, wget, httpie Tutorial

Tutorial for using the OpenCage Geocoding API in curl, wget, httpie - An API for reverse and forward geocoding using open geo data

## Using the OpenCage Geocoding API from the command line

The API is is accessed via an HTTP GET request with a few parameters. There is no need to set any headers or cookies. Note that you will need to URI encode the query for forward geocoding (address to coordinates) requests.

### curl

    # reverse geocoding
    curl 'https://api.opencagedata.com/geocode/v1/json?q=-23.5373732,-46.8374628&pretty=1&key=YOUR-API-KEY'
    
    # forward
    curl 'https://api.opencagedata.com/geocode/v1/json?q=Pappelallee+78%2F79,+10437+Berlin,+Germany&pretty=1&key=YOUR-API-KEY'

### HTTPie

    http GET https://api.opencagedata.com/geocode/v1/json q==-23.5373732,-46.8374628 pretty==1 key==YOUR-API-KEY

### wget

    wget 'https://api.opencagedata.com/geocode/v1/json?q=-23.5373732,-46.8374628&pretty=1&key=YOUR-API-KEY' -O results.json

### OpenCage CLI tool

We provide an installable command line tool to geocode CSV files. It supports parallel requests, selecting input and output columns, progress bar, error handling. Requires Python 3.9 or newer.

See our full [geocoding CLI tutorial](https://opencagedata.com/tutorials/geocode-commandline).

    pip install opencage-cli
    opencage -h
    
    cat coordinates.csv
    49.403370,2.325642
    48.048349,-1.601447
    44.504731,1.188501
    43.606452,-1.381768
    
    opencage reverse --api-key YOUR-API-KEY --input coordinates.csv --output results.csv --add-columns country,formatted
    
    cat results.csv
    49.403370,2.325642,France,"1 Rue du Général Leclerc, 60510 La Neuville-en-Hez, France"
    48.048349,-1.601447,France,"9 Allée du Close Suzan, 35770 Vern-sur-Seiche, France"
    44.504731,1.188501,France,"1 Rue du Quercy, 46220 Prayssac, France"
    43.606452,-1.381768,France,"1635 Route du Tuc, 40230 Orx, France"

 ![Commandline example of using batch.py](https://assets.opencagedata.com/assets/tutorials/cli-b65521f61dbc1549db9a4421d546021a6d11c8cadd6aff8d2e0f8c5b29806dd2.gif)

### Further Reading

- [OpenCage geocoding API Reference](https://opencagedata.com/api)
- [Comparing geocoding services](https://opencagedata.com/guides/how-to-compare-and-test-geocoding-services)
- [Cleaning / formatting your forward geocoding query](https://opencagedata.com/guides/how-to-format-your-geocoding-query)
- [Geocoding more quickly](https://opencagedata.com/guides/how-to-geocode-more-quickly)
- [Geocoding large datasets](https://opencagedata.com/guides/how-to-geocode-large-datasets)
- [Geocoding and preserving privacy](https://opencagedata.com/guides/how-to-preserve-privacy-by-showing-only-an-imprecise-location)
- [Sample address and coordinate lists for testing](https://opencagedata.com/tools/address-lists)

