• Skip to primary navigation
  • Skip to main content
Ethan Banks

Ethan Banks

@ecbanks

  • Blog
  • Book
  • Podcasts
  • RSS
  • Show Search
Hide Search

How To Pass API Query Parameters In A Curl Request

Ethan Banks · < 1 minute to read
Published February 7, 2022 · Updated February 7, 2022

If you’re using CLI tool curl to retrieve data from a remote API, you might send forth a command like so.

curl -H "Authorization: Bearer access_token_goes_here" \
  https://api.provider.com/thing/you_want/index.json

That results in a lovely JSON payload that makes you happy.

Let’s say that according to the API documentation, /thing/you_want/ accepts query parameters so that you can scope what you want to know about. Excellent! Instinctively, you try the following…

curl -H "Authorization: Bearer access_token_goes_here" \
  https://api.provider.com/thing/you_want/index.json?scope=1

Rather than a scoped JSON payload that also makes you happy, you get back a message indicating that the API endpoint is displeased. Your sacrifice was deemed unworthy. Nay, YOU are unworthy. You are decidedly not happy.

What has gone wrong to anger the API gods so? You asked the wrong question of the API. More accurately, curl hasn’t formatted the request in quite the way you intuited it would.

To appease the API deities, the appropriate sacrifice comes in the form of a tweaked curl command. For example…

curl -G -H "Authorization: Bearer access_token_goes_here" \
  https://api.provider.com/thing/you_want/index.json \
  -d "query=scope=1"

We added a “-G” flag to make sure curl is sending a GET and not a POST. We also added a -d (for data) with the value of the API query parameter to be sent.

For More Information

linux man page on curl – read the section on “G/–get”

Filed Under: Hands OnPublished on ethancbanks.com.

Have You Read…?

  1. What Does An ‘R’ Before A String Mean In Python?
  2. How To Pass API Query Parameters In A Curl Request
  3. Synology Running Out Of Space? Empty The Recycle Bin.
  4. Free Networking Lab Images From Arista, Cisco, nVidia (Cumulus)
  5. How To Create A Python Function You Can Call From Other Scripts
  6. How To Use Grep + Regex To Match Non-200 HTTP Status Codes In Apache Server Logs
  7. When Stretching Layer Two, Separate Your Fate
  8. How To: Simple Juniper SRX Rate-Limiting via Policer
  9. Using AppleScript To Size A Window To 16×9 On MacOS
  10. Auto-Adding Routes When Mac PPTP Connection Comes Up

MORE FREE STUFF!

Check out my IT Education Twitter Collection.
Curated tweets for IT professionals trying to up their game.

twitter mastodon linkedin instagram linkedin

Have a great day. You're doing an outstanding job. 👍

About · Privacy

Copyright © 2007–2023 Ethan Banks