{"pageProps":{"user":null,"pages":[{"id":8,"title":"Getting Started","slug":"getting-started","level":1,"parent_id":null},{"id":9,"title":"Getting Started","slug":"getting-started","level":2,"parent_id":3},{"id":2,"title":"Quick Start","slug":"quick-start","level":1,"parent_id":null},{"id":3,"title":"GUI Reference","slug":"gui-reference","level":1,"parent_id":null},{"id":4,"title":"API Reference","slug":"api-reference","level":1,"parent_id":null},{"id":10,"title":"Get","slug":"get","level":2,"parent_id":4},{"id":12,"title":"Database Reference","slug":"database-reference","level":1,"parent_id":null},{"id":11,"title":"Post","slug":"post","level":2,"parent_id":4},{"id":13,"title":"Data types","slug":"data-types","level":2,"parent_id":12},{"id":14,"title":"Querying Data","slug":"querying-data","level":2,"parent_id":12},{"id":15,"title":"Upload Media","slug":"upload-media","level":2,"parent_id":3}],"targetPage":{"title":"API Reference","slug":"api-reference","description":"
Access data from external sources. Datasquirel is platform-agnostic so all you need is a HTTP request with the right credentials. Our NPM module abstracts this aspect for ease of use when using node.
","content":"All data stored in your databases can be accessed through our integrated API. There are two sets of API keys, each with different scope. If you want to just fetch data use the Read Only API key. If you want to have full access to every aspect of your account, use the Full Access API key. Learn how to add API keys here.
After you have your API keys, you can start making calls using our API integration. We have an NPM module for node projects, but you only need a HTTPS client to make the calls.
npm install datasquirel
The get method only retrieves data. It cannot be used to write or update data. It was created to be the fastest way to access your data, that explains the key length. You can get data using the npm module or via any HTTP request.
CURL \n https://datasquirel.com/api/query/get?db=db_name&query=SELECT+*+FROM+table_name \n-H \n \"Authorization:READ_ONLY_API_KEY\";Content-Type:application/json
const datasquirel = require(\"datasquirel\");\n\ndatasquirel\n .get({\n db: \"test\",\n key: process.env.DATASQUIREL_READ_ONLY_KEY,\n query: \"SELECT title, slug, body FROM blog_posts\",\n })\n .then((response) => {\n console.log(response);\n });
The response from this method returns a JSON payload with two fields: success: which could be either true
or false
, and payload: which is an array of values when the operation is successfull, or anything from null
to a string to an object with an error message. This is a sample of a successful response object:
{\n success: true,\n payload: [\n {\n id: 1,\n title: \"Hello World\",\n slug: \"hello-world\",\n body: \"This is a test blog post.\",\n },\n ],\n}
A failed response could return any of three results:
null
payload.{\n success: false,\n payload: null\n}
{\n success: false,\n payload: \"ERROR: no such table as 'blog_posts'\"\n}
{\n success: false,\n payload: { error: \"MYSQL ERROR: syntax error in your sql\" }\n}
In each case, the success key refurns a value of false
, meaning the query failed.
The post method contains the full spectrum of CRUD operations. And it works *only with the Full Access API key. The read only API key will not work for post methods.
CURL --json\n '{ \n \"database\": \"social_network\",\n \"query\": \"UPDATE users SET name = 'John' WHERE id = 1\"\n }'\n https://datasquirel.com/api/query/post \n-H \n \"Authorization:FULL_ACCESS_API_KEY\"`
const datasquirel = require(\"datasquirel\");\n\ndatasquirel\n .post({\n database: \"social_network\",\n key: process.env.FULL_ACCESS_API_KEY,\n query: \"UPDATE users SET name = 'John' WHERE id = 1\",\n })\n .then((response) => {\n console.log(response);\n });
The process yeilds simalar results, but with a slight difference: for operations like insert and update, the success
field yeilds true
while the payload
field yeilds an object containing fields like
{\n success: true,\n payload: {\n serverStatus: 37,\n affectedRows: 1,\n }\n}
The post method can also take an object as the query
instead of a string. Example:
const datasquirel = require(\"datasquirel\");\n\ndatasquirel\n .post({\n database: \"social_network\",\n key: process.env.FULL_ACCESS_API_KEY,\n query: {\n action: \"update\",\n table: \"users\",\n data: {\n name: \"John\",\n },\n identifierColumnName: \"id\",\n identifierValue: 1,\n },\n })\n .then((response) => {\n console.log(response);\n });
This yields the exact same result as before. Learn more about the post method here.
"}},"__N_SSG":true}