U.S. flag

An official website of the United States government

Access the API: Command Line

Step 1: Open and change drives/folders

To start, open a command line software. For Windows, this might be called “Command Prompt” and for Mac or Linux, it might be called “Terminal”.

For Windows users, the command line will open in a particular drive, such as C: for the C drive. To change drives, type a different letter followed by a colon (G:) and hit Enter.

DSID API Example Response

For Mac/Linux users, the command line will open in a folder. To check the path to the current folder, use the pwd command.

For this example, we suggest using the cd command to navigate to a folder you want to store the output in (such as DSID) and creating a new folder (mkdir my_api_requests) in your file explorer.

DSID API Example Response

Step 2: Add header

Start by typing curl after the > symbol.

DSID API Example Response

Headers are a way to pass metadata about a request to the API. In this case, you can specify that you want to provide input data in JSON format. Add a space and enter the following text:

DSID API Example Response

Your current request now looks like this:

DSID API Example Response

Step 3: Add request type

To specify the type of API request, add another space and type “--request POST”:

DSID API Example Response

Your current request now looks like this:

DSID API Example Response

Step 4: Add data

Add the --data tag before adding raw JSON data, followed by a space.

DSID API Example Response
Example goal: Estimate calcium levels in adult MVMs using a label amount of 200mg. This will use four input fields:
  • "study_code": "01"
  • "ingredient": "calcium"
  • "label_amount": 200
  • "unit": "mg"

To add the data inJSON directly into the command line (see Appendix for using an input file instead), start with a set of square [ ] and curly { } brackets, and paste in the data above, separating each field by a comma.

DSID API Example Response

Next, add double quote marks before and after the square brackets. For each quotation mark inside the query, add a backslash to escape it: \". This allows it to recognize the inner quote marks as well as the ones surrounding the whole query.

DSID API Example Response

Your current request looks like this:

DSID API Example Response

Step 5: Add the URL

Finally, add the URL for the DSID calculator API endpoint: https://dsid-api-dev.app.cloud.gov/v1/calculators

The full curl input should now look like this. Use the right arrow key to get to the end of the text and hit enter to submit the request.

DSID API Example Response

The output should return from the DSID API in JSON format, right in your command window.

DSID API Example Response

Step 6: Saving output to a file

This output can become long for larger requests. To output the results to a file, you can add a > symbol and a filename to the end of the request:

DSID API Example Response

See this example of what your output file should look like: output_from_curl.json

Appendix: Using a JSON input file

For larger requests, you may choose to use an input file instead of pasting the raw JSON data in like you did in Step 4.

To do so, first store your input fields in a JSON file such as “input.json”. Then add the data using double quotes, an @ symbol and your filename:

DSID API Example Response

The rest of the request can remain the same:

DSID API Example Response

You can now work with this output in your preferred software program. See the Converting JSON Data API page for importing into Excel.