Skip to content

Instantly share code, notes, and snippets.

@jeszy75
Last active August 31, 2020 14:54
Show Gist options
  • Save jeszy75/841f9a396cc0defc31ab2c01b3bcec29 to your computer and use it in GitHub Desktop.
Save jeszy75/841f9a396cc0defc31ab2c01b3bcec29 to your computer and use it in GitHub Desktop.
Using the jsonbin.io API with HTTPie

API Documentation

See: https://jsonbin.io/api-reference

First Steps

Execute the following commands after registration:

rm -f jsonbin.json
http --session=./jsonbin.json https://api.jsonbin.io/ 'secret-key:<secret-key>' -v
cat jsonbin.json

The secret key to be substituted into the command above can be found here (requires login): https://jsonbin.io/api-keys.

In the following, HTTPie will include the secret-key header field with the secret key in subsequent requests when the --session-read-only=./jsonbin.json command line option is specified.

Basic Use

Example (1)

Uploading JSON data with public visibility:

http --session-read-only=./jsonbin.json https://api.jsonbin.io/b name:hello private:false text="Hello, World!" -v

Your uploaded data is available here (requires login): https://jsonbin.io/dashboard.

Querying data by the identifier ("id") provided in the response:

http https://api.jsonbin.io/b/<id> -v

Example (2)

Uploading JSON data with private visibility:

http --session-read-only=./jsonbin.json https://api.jsonbin.io/b name:credentials private:true username=admin password=secret -v

Querying data by the identifier ("id") provided in the response:

http https://api.jsonbin.io/b/<id> -v # Error (Unauthorized)
http --session-read-only=./jsonbin.json https://api.jsonbin.io/b/<id> -v

Example (3)

Uploading JSON data from the file system:

http https://api.thetvdb.com/series/80379 -d -o The_Big_Bang_Theory.json
http --session-read-only=./jsonbin.json https://api.jsonbin.io/b name:The_Big_Bang_Theory private:false @The_Big_Bang_Theory.json -v

Example (4)

Deleting JSON data:

http --session-read-only=./jsonbin.json DELETE https://api.jsonbin.io/b/<id> -v

The returned status code is 502 (Bad Gateway), however, the bin is deleted.

Example (5)

Downloading some JSON data for testing purposes:

http https://api.thetvdb.com/series/121361 -d -o Game_of_Thrones.json
http https://api.thetvdb.com/series/153021 -d -o The_Walking_Dead.json

Creating a collection:

http --session-read-only=./jsonbin.json https://api.jsonbin.io/c name="TheTVDB Data" -v

Storing test data in the newly created collection based on the identifier ("id") provided in the response:

http --session-read-only=./jsonbin.json https://api.jsonbin.io/b name:Game_of_Thrones private:false collection-id:<id> @Game_of_Thrones.json -v
http --session-read-only=./jsonbin.json https://api.jsonbin.io/b name:The_Walking_Dead private:false collection-id:<id> @The_Walking_Dead.json -v

Your collections can be found here (requires login): https://jsonbin.io/dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment