{"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":"Post","slug":"post","description":"
Full CRUD operations on your database using our feature-rich API integration.
","content":"The post method expands on the get method. It adds the ability to insert, update, and delete data, as well as add and delete images from your static files directories.
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.
In addition to the full CRUD operations the post method offers, you can also add media to your static files directory. This uses the same post method, but with sligtly different parameters. Also, the media you send *must be in base64 format. You can use our npm client module to convert images and documents to base64 format.
const datasquirel = require(\"datasquirel\");\n\ndatasquirel.media\n .uploadImage({\n key: process.env.DATASQUIREL_FULL_ACCESS_API_KEY,\n payload: {\n imageData: \"--------- LONG BASE64 STRING ---------\",\n imageName: \"sunflower\",\n folder: \"flowers\", // Optional\n mimeType: \"jpeg\", // Optional\n thumbnailSize: 300, // Optional\n },\n })\n .then((response) => {\n console.log(response);\n });"}},"__N_SSG":true}