You can attach a Schema Validation doc to your Collection. This helps to validate the records based on the Schema Doc validation rules.
Root
https://api.jsonbin.io/v3
Route
/c/<COLLECTION_ID>/schemadoc/add
Request Type
PUT
Request Headers
Header | Value | Required |
X-Master-Key | <YOUR_SECRET_KEY> | Yes |
X-Schema-Doc-Id | <SCHEMA_ID>> | Yes |
X-Master-Key
X-Master-Key is required to Update a Collection. You can find your X-Master-Key on the API Keys page after signing-in.
X-Schema-Doc-Id
You need to pass X-Schema-Doc-Id header with the Schema Doc ID which you need to attach to the Collection.
Basic Code Samples
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/<COLLECTION_ID>/schemadoc/add'
headers = {
'X-Schema-Doc-Id': '<SCHEMA_DOC_ID>',
'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 200
{
"collectionName": "<COLLECTION_NAME>",
"schemaDocId": "<ATTACHED_SCHEMA_DOC_ID",
"metadata": {
"id": "<COLLECTION_ID>",
"createdAt": "2020-12-16T20:13:22.116Z"
}
}
Error 400, 401, 403
{
"message": "<ERROR_MESSAGE>"
}
Status Code | Error Message |
---|---|
401 Unauthorized |
You need to pass X-Master-Key in the header |
400 Bad Request |
Invalid Collection Id provided |
400 Bad Request |
You need to pass X-Schema-Doc-Id in the header |
400 Bad Request |
Invalid Schema Id provided |
404 Not Found |
Collection not found |
401 Unauthorized |
Invalid X-Master-Key provided |
401 Unauthorized |
You cannot attach a Schema Doc to Validate your Collection. Consider upgrading to the Pro plan. |
403 Forbidden |
You cannot create more than 10 collections. Please delete a Collection and try again. |
404 Not Found |
Schema Doc not found |
403 Forbidden |
Requests exhausted. Buy additional requests at https://jsonbin.io/pricing |