# API

## Introduction <a href="#introduction" id="introduction"></a>

The API reference documentation provides detailed information for each of the methods and endpoints of the platform.

The information can be used for reporting, reading collections, and accessing routes on the platform.

We have language bindings in NodeJs, C#, and Python! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

## Getting Started <a href="#getting-started" id="getting-started"></a>

For application development please refer [developer guide](https://www.obto.co/site/ob/documentation).

## Platform Library <a href="#platform-library" id="platform-library"></a>

### Print <a href="#print" id="print"></a>

```
ob.print(<log>)
```

This code is used to print logs.

### Request (HTTP: GET,POST,PUT,DELETE) <a href="#request-http-get-post-put-delete" id="request-http-get-post-put-delete"></a>

```
ob.request()
```

This code is used to prepare requests to external API/Endpoints

### Fetch All Sub-domains <a href="#fetch-all-sub-domains" id="fetch-all-sub-domains"></a>

```
ob.alldomains(<domain>)
```

This code is used to get all domains on the instance

### Check For Top Domain <a href="#check-for-top-domain" id="check-for-top-domain"></a>

```
ob.isTop(<domain_name>)
```

This code is used to check the .

### Encryption <a href="#encryption" id="encryption"></a>

```
ob.utils.encrypt(<text>)
```

This code is used to encrypt text.

### Decryption <a href="#decryption" id="decryption"></a>

```
ob.utils.encrypt(<text>)
```

This code is used to decrypt text.

### Publish Via Emma <a href="#publish-via-emma" id="publish-via-emma"></a>

```
ob.emma.publish(<message>)
```

This code is used publish message to a topic.

### Log message <a href="#log-message" id="log-message"></a>

```
ob.log(<message>)
```

This code is used to log text.

### Get Property <a href="#get-property" id="get-property"></a>

```
ob.getProperty(<property_name>)
```

This code is used to get property.

### Fetch Global Properties <a href="#fetch-global-properties" id="fetch-global-properties"></a>

```
ob.getGloablProps()
```

This code is used to fetch all global properties.

### Send Email <a href="#send-email" id="send-email"></a>

```
ob.sendMailv2(<Email object>)
```

This code is used to send email.

### Send SMS <a href="#send-sms" id="send-sms"></a>

```
ob.sendSMS(<SMS Object>)
```

This code is used to send SMS.

### Run Aggregation <a href="#run-aggregation" id="run-aggregation"></a>

```
ob.agg(<message>)
```

This code is used to run DB Aggregation.

### Run User Script <a href="#run-user-script" id="run-user-script"></a>

```
ob.runScript(<user_script>)
```

This code is used to run user script.

### Check If Edu Collection <a href="#check-if-edu-collection" id="check-if-edu-collection"></a>

```
ob.isEdu(<collection_name>)
```

This code is used to check if the collection belong to EDU domain.

### Sign Token <a href="#sign-token" id="sign-token"></a>

```
ob.sign(<message>)
```

This code is used to sign and return user token.

### Database API <a href="#database-api" id="database-api"></a>

Database API is accessible via the global "ob" object as "ob.db".

#### getCount = function (collection, query, options, \_callback) <a href="#getcount-function-collection-query-options-_callback" id="getcount-function-collection-query-options-_callback"></a>

#### findDistinct = function (collection, key, query, options, \_callback) <a href="#finddistinct-function-collection-key-query-options-_callback" id="finddistinct-function-collection-key-query-options-_callback"></a>

#### findAndModify = function (collection, query, sort, replacement, options, \_callback) <a href="#findandmodify-function-collection-query-sort-replacement-options-_callback" id="findandmodify-function-collection-query-sort-replacement-options-_callback"></a>

#### findStream = function (tableName, query, options, \_eod, \_com) <a href="#findstream-function-tablename-query-options-_eod-_com" id="findstream-function-tablename-query-options-_eod-_com"></a>

#### agg = function (collection, agg, \_eod, \_com) <a href="#agg-function-collection-agg-_eod-_com" id="agg-function-collection-agg-_eod-_com"></a>

#### create = function (tableName, \_data, options, \_callback) <a href="#create-function-tablename-_data-options-_callback" id="create-function-tablename-_data-options-_callback"></a>

#### createMultiple = function (tableName, \_data, options, \_callback) <a href="#createmultiple-function-tablename-_data-options-_callback" id="createmultiple-function-tablename-_data-options-_callback"></a>

#### update = function (tableName, query, options, options2, options3, \_callback) <a href="#update-function-tablename-query-options-options2-options3-_callback" id="update-function-tablename-query-options-options2-options3-_callback"></a>

#### updateMany = function (collection, query, options, options2, options3, \_callback) <a href="#updatemany-function-collection-query-options-options2-options3-_callback" id="updatemany-function-collection-query-options-options2-options3-_callback"></a>

#### listCollections = function (filter, \_callback) <a href="#listcollections-function-filter-_callback" id="listcollections-function-filter-_callback"></a>

#### readFile = function (fileId, res, opts) <a href="#readfile-function-fileid-res-opts" id="readfile-function-fileid-res-opts"></a>

## API Query <a href="#api-query" id="api-query"></a>

Querying DB via HTTP Endpoints is really easy and follows a simple key value pair standard.

Example:

Consider a collection name **TASK**

It has following fields :

| Fields      | Type      | Description |
| ----------- | --------- | ----------- |
| name        | text      |             |
| amount      | number    |             |
| created\_on | datetime  |             |
| manager     | reference |             |

### Text Queries <a href="#text-queries" id="text-queries"></a>

#### Query on single field <a href="#query-on-single-field" id="query-on-single-field"></a>

`oquery=name=Dave Smith`

#### Query on multiple fields <a href="#query-on-multiple-fields" id="query-on-multiple-fields"></a>

`oquery=name=Dave Smith,amount=0`

#### Starts With Query <a href="#starts-with-query" id="starts-with-query"></a>

`oquery=name==Dave Smith`

#### Does Not Starts with Query <a href="#does-not-starts-with-query" id="does-not-starts-with-query"></a>

`oquery=name=!=Dave`

#### Contains Query <a href="#contains-query" id="contains-query"></a>

`oquery=name=*Dave`

#### Does Not Contain Query <a href="#does-not-contain-query" id="does-not-contain-query"></a>

`oquery=name=!*Dave`

### Number Queries <a href="#number-queries" id="number-queries"></a>

#### Equals Than <a href="#equals-than" id="equals-than"></a>

`oquery=amount===0`

#### Greater Than <a href="#greater-than" id="greater-than"></a>

`oquery=amount=>0`

#### Less Than <a href="#less-than" id="less-than"></a>

`oquery=amount=<0`

### Date Queries <a href="#date-queries" id="date-queries"></a>

#### Today <a href="#today" id="today"></a>

`oquery=created_on=today`

#### Yesterday <a href="#yesterday" id="yesterday"></a>

`oquery=created_on=yesterday`

#### Day Before Yesterday <a href="#day-before-yesterday" id="day-before-yesterday"></a>

`oquery=created_on=daybeforeyesterday`

#### Custom <a href="#custom" id="custom"></a>

`oquery=created_on=#in2018-07`

`oquery=created_on=on2018-07-15`

## Plarform Endpoints <a href="#plarform-endpoints" id="plarform-endpoints"></a>

### Authentication <a href="#authentication" id="authentication"></a>

> To obtain an access token, use this code:

```
```

> Make sure to replace `Username & Password` with your login credentials.

SOFOS uses API keys to allow access to the API. You can register a new SOFOS API key at our [developer portal](https://www.obto.co/site/ob/documentation).

SOFOS expects a security tokem to be included in all API requests to the server in a header that looks like the following:

`Authorization: Bearer`

This endpoint retrieves all kittens.

#### HTTP Request <a href="#http-request" id="http-request"></a>

`POST http://*.obto.co/auth`

#### Query Parameters <a href="#query-parameters" id="query-parameters"></a>

| Parameter  | Default | Description                           |
| ---------- | ------- | ------------------------------------- |
| user\_name | NA      | Your user name which is used to login |
| password   | NA      | Your password which is used to login  |

### Important <a href="#important" id="important"></a>

Every collection in SOFOS is accessible via a HTTP API.

Example :

https\://\*.obto.co/o/recs/?stream=true\&project=\&oquery=

```
```

```
```

### Fetch API <a href="#fetch-api" id="fetch-api"></a>

```
```

```
```

```
```

This endpoint retrieves a data from a specified collection.

#### HTTP Request <a href="#http-request-2" id="http-request-2"></a>

`GET https://*.obto.co/o/recs/?stream=true&project=&oquery=`

#### URL Parameters <a href="#url-parameters" id="url-parameters"></a>

| Parameter  | Value | Description                           |
| ---------- | ----- | ------------------------------------- |
| stream     | true  | The ID of the kitten to retrieve      |
| projection |       | comma seperate list of fields to show |
| oquery     |       | See API Query Builder                 |

### Post API <a href="#post-api" id="post-api"></a>

```
```

```
```

```
```

This endpoint will create a new record in the collection specified

#### HTTP Request <a href="#http-request-3" id="http-request-3"></a>

`POST https://*.obto.co/o/`

#### POST Body <a href="#post-body" id="post-body"></a>

| Body      | Description       |
| --------- | ----------------- |
| Json Data | Data to be posted |

## Errors <a href="#errors" id="errors"></a>

The SOFOS API uses the following error codes:

| Error Code | Meaning                                                                                   |
| ---------- | ----------------------------------------------------------------------------------------- |
| 400        | Bad Request -- Your request is invalid.                                                   |
| 401        | Unauthorized -- Your API key is wrong.                                                    |
| 403        | Forbidden -- The kitten requested is hidden for administrators only.                      |
| 404        | Not Found -- The specified kitten could not be found.                                     |
| 405        | Method Not Allowed -- You tried to access a kitten with an invalid method.                |
| 406        | Not Acceptable -- You requested a format that isn't json.                                 |
| 410        | Gone -- The kitten requested has been removed from our servers.                           |
| 418        | I'm a teapot.                                                                             |
| 429        | Too Many Requests -- You're requesting too many kittens! Slow down!                       |
| 500        | Internal Server Error -- We had a problem with our server. Try again later.               |
| 503        | Service Unavailable -- We're temporarily offline for maintenance. Please try again later. |
