< Back

Test with curl

curl (short for Client URL) is a command-line application for sending and receiving data over HTTP. It’s commonly used to test APIs, retrieve resources, and post data directly from a terminal.

You can use curl to authenticate, query, and validate your Health Gorilla API integration without relying on external applications. This procedure helps you set up environment variables, construct reusable commands, and run test requests.

To configure curl and test API operations

  1. In your shell, enter the following variable values based on your credentials and API setup.
  • CLIENT_ID: Your OAuth client ID
  • CLIENT_SECRET: Your OAuth client secret
  • BASE_URL: Your base FHIR endpoint (for example, https://sandbox.healthgorilla.com/fhir/R4)
  • ACCESS_TOKEN: Your OAuth bearer token (added after token generation)

Example:

export CLIENT_ID="your_client_id"
export CLIENT_SECRET="your_client_secret"
export BASE_URL="https://sandbox.healthgorilla.com/fhir/R4"
export ACCESS_TOKEN="your_access_token"
  1. Optionally, create a script to preload credentials by saving the variable exports in a file such as hg_curl_setup.sh, then run it before testing:
source hg_curl_setup.sh

  1. Run a test API call to retrieve a FHIR resource and verify connectivity. For example, use the following example to retrieve a patient allergy record.
curl -X GET "$BASE_URL/AllergyIntolerance/12345" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Accept: application/fhir+json"
  1. Confirm that the API returns a valid FHIR resource in JSON format.

Troubleshooting

To troubleshoot possible errors, follow these steps:

  • 401 Unauthorized: Verify the access token and headers, then try again
  • 404 Not Found: Confirm the resource ID and endpoint path
  • 500 Internal Server Error: Retry later or contact Support if the problem persists

Summary

Testing with curl allows you to verify your credentials, confirm endpoint connectivity, and inspect FHIR resource responses directly from the command line. Once authenticated, you can reuse the same setup to test other resources such as Patient, Observation, or DocumentReference.