Add Schema API

You could use Collections to group the bins of a specific kind. Other reasons to use Collections is to validate your JSON records.

A Schema Doc can be attached to the Collection using Add Schema API.

Root

https://api.jsonbin.io/v3 

Route

/c/<COLLECTION_ID>/schemadoc/add 

Request Type

PUT

Request Headers

Below are the list of Accepted Request Headers if you are trying to Attach a Schema Doc to a Collection.

Request Header Value Required
X-Master-Key <API_KEY> Yes
X-Schema-Doc-Id <SCHEMA_ID> Yes
X-Master-Key Required

X-Master-Key is nothing but your Core API Access Key. You will need this Key to access mostly any API end-point on JSONBin. You could find the key on the API Keys page.

X-Schema-Doc-Id Required

You need to pass X-Schema-Doc-Id which you wish to attach to the Collection.

Code Samples

  • cURL
  • JavaScript (ES6)
  • Python 3
  • Ruby
curl -v\
  -H "X-Schema-Doc-Id: <SCHEMA_DOC_ID>" \
  -H "X-Master-key: <YOUR_API_KEY>" \
  --request PUT \
    https://api.jsonbin.io/v3/c/<COLLECTION_ID>/schemadoc/add
let req = new XMLHttpRequest();

req.onreadystatechange = () => {
  if (req.readyState == XMLHttpRequest.DONE) {
    console.log(req.responseText);
  }
};

req.open("PUT", "https://api.jsonbin.io/v3/c/<COLLECTION_ID>/schemadoc/add", true);
req.setRequestHeader("X-Schema-Doc-Id", "<SCHEMA_DOC_ID>");
req.setRequestHeader("X-Master-Key", "<YOUR_API_KEY>");
req.send();
import requests
url = 'https://api.jsonbin.io/v3/c'
headers = {
  'X-Collection-Name': 'My Collection',
  'X-Master-Key': '<YOUR_API_KEY>'
}
data = {}

req = requests.post(url, json=data, headers=headers)
print(req.text)
require 'net/http'
require 'json'

uri = URI("https://api.jsonbin.io/v3/c/<COLLECTION_ID>/schemadoc/add")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
  req = Net::HTTP::Put.new(uri)
  req['X-Schema-Doc-Id'] = '<SCHEMA_DOC_ID>'
  req['X-Master-Key'] = '<YOUR_API_KEY>'
  
  http.request(req)
end

puts res.body

Request Response

Success Status Code: 200
{
  "collectionName": "<COLLECTION_NAME>",
  "schemaDocId": "<ATTACHED_SCHEMA_DOC_ID>",
  "metadata": {
     "id": "<COLLECTION_ID>",
     "createdAt": "<DATE/TIME>"
   }
}
Error Status Code: 400, 401, 403, 404
{
  "message": "<Error Message>"
}

For more information on the error codes & errors you might possibly encounter, refer to the below section.

Error Reference

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
Invalid X-Collection-Id provided

Check if the X-Collection-Id is valid and belongs to your account.

You need to pass X-Schema-Doc-Id in the header

X-Schema-Doc-Id need to be passed to attach it to the Collection.

Invalid Schema Id provided

The Schema Id you've provided is invalid or does not belong to your account.

Invalid X-Master-Key provided

Check if the X-Master-Key you've provided is valid.

You cannot attach a Schema Doc to Validate your Collection. Consider upgrading to the Pro plan.

You need to upgrade to the Pro plan to attach a Schema to a Collection.

Requests exhausted. Buy additional requests at https://jsonbin.io/pricing

You'll encounter this error if you've consumed all the available requests. You can purchase additional requests.

Collection not found

The Collection you are trying to attach the Schema to does not exists

Schema Doc not found

The Schema Doc you are trying to attach to the Collection does not exists.

Create a Free Account

Create an Account View Pricing