WideDB
Log In
Sign Up Free
 

WideDB API

Introduction

WideDB allows to get/create/update records with simple REST JSON requests. In this guide, you’ll learn the basics of how to manage your data via the API.

Step 1. Create access group.

To provide API access to your database you need to a new access group first. Open the designer panel, click the "Access" button, click the "Create New Access Group" button:

Select the "API Access" group type: And click the "Create" button.

Don't forget to specify "Tables Access" for this new API.

To get Access Key click the "Show access key" button:

Remember the key. We will use it to authorize.

Step 2. Sending API Request.

The WideDB API uses POST requests for interacting with records.

Each POST request should contain only one JSON object named "data" with all options in it.

Here is an example of a simple request (PHP):

$data= array ( 'key'=>'m7q3iy3sfl3dtl7shxbb8', 'action'=>'new', 'table'=>'Items', 'recs'=>array(array('Title'=>'Hello from API','Price'=>120.23)) ); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,"https://widedb.com/x&t=api"); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data)); $result = curl_exec($ch);

Parameters

There are 3 main parameters required for all requests:

  • key - API group access key (see step 1);
  • table - Database table you want to work with;
  • action - Action to execute:
    • new - create new records in the database;
    • delete - delete records in the database;
    • update - update records in the database;
    • select - get record field values from the database by rule.

Additional parameters for "new/update/delete" actions:

  • recs - Simple array of records. Each record is an JSON associative array (field=value). To identify a record (to update/delete) - specify the record "jid".

Additional parameters for the "select" action:

  • rule - Rule to select records by (string). Field names must be in square brackets, string values in quotes. You can use AND/OR and simple brackets. Example: [Price]>100 AND ([Title] ~ “water” OR [Title] ~ “juice”);
  • order - Order string (optional). Example: [Group], [Price] desc;
  • from - Return records starting from number (optional, default - 0);
  • limit - Maximum number of records to return (optional, the default - 1000).

Examples of Requests (data)

Creating 2 new records in the table named "Items":

{ key: 'm7qwerty', action: 'new', table: 'Items', recs: [{'Title': 'Apple', 'Price': '10.50'}, {'Title': 'Orange','Price': '13.95'}] }

Updatind 2 records in the table named "Items":

{ key: 'm7qwerty', action: 'update', table: 'Items', recs: [{'jid'=>'m3e4123', 'Price': '10.90'}, {'jid'=>'m3e4125', 'Price': '15.95', 'Title': 'Granny Sm.'}] }

Deleting 3 records in the table named "Items":

{ key: 'm7qwerty', action: 'delete', table: 'Items', recs: [{'jid'=>'m3e4123'}, {'jid'=>'m3e4125'}, {'jid'=>'m3e4129'}] }

Requesting first 5 most expensive Items containing the string "water" in the "Title" field:

{ key: 'm7qwerty', action: 'select', table: 'Items', rule: '[Title] ~ "water"', order: '[Price] desc', limit: 5 }

Step 3. API Response.

API response is a JSON string in case of successful execution or "0 error_description" n case of error.

Each successful response has the following parameters:

  • warnings - simple array of non-critical errors;
  • rec_select_count - the number of records returned by the "select" action;
  • rec_new_count - the number of records created by the "new" action;
  • rec_update_count - the number of records updated by the "update" action;
  • rec_delete_count - the number of records deleted by the "delete" action;
  • recs - array of records selected by the "select" action;
  • rec_new_jids - simple array of JID of new records, created by the "new" action.
PRODUCT
SUPPORT
LEGAL

WideDB is online database
application constructor

LOG IN | TRY FOR FREE
Copyright (C) 2013-2018, Binary Brilliant Inc, All rights reserved.