# Accelerator Platform - Core APIs

The Accelerator Platform Core APIs allow developers to quickly create databases (Organizations), relational tables called Objects, and CRUD API Endpoints with validation and business logic.

Authentication: To test the APIs described below, authentication as a Project Admin in the Accelerator Platform is required. Further information can be found in the Accelerator Platform IAM documentation.

Organizations: Within an Accelerator Platform project, it is possible to create multiple organizations, each of which represents a MongoDB database containing objects. By default, each organization includes two fields: name and domain. The organization metadata is stored in an Object called "Org", which can be extended with additional fields, similar to any other Object.

```
// Example 1:
    Step 1. Create a new Organization
    POST https://qa.accelerator-platform.com/api/v1/Organizations
    Request Header:
    {
        "Authorization": "bearer <Project-Admin-AuthToken>"
    }
    Request Body:
    {
    "name": "Clinic",
    "domain": "clinic"
    }
    Response Body:
  200
    <Organization-Id>
 400 
{ 
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1", 
 "title": "One or more validation errors occurred.", 
 "status": 400, 
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00", 
 "errors": { ... } 
}
401 
Unauthorized
403
forbidden
    To Get the Organization
    Request Header:
    {  "Authorization": "bearer <Project-Admin-AuthToken>"  }
    GET https://qa.accelerator-platform.com/api/v1/GetOrganization/<Organization-Id>
    To Get all Organizations
    Request Header:
    {  "Authorization": "bearer <Project-Admin-AuthToken>"  }
    GET https://qa.accelerator-platform.com/api/v1/GetOrganizations

```

Objects: Object metadata is stored in a MongoDB collection called "objects" within the organization database. When creating an Object, users can add fields to the object, and define validation rules and business logic for each field. below is a list of all the attributes of an Object.

(Attributes that starts with underscore (\_) are read-only and cannot be modified)

<table data-header-hidden><thead><tr><th width="213">Name</th><th width="125">Data type</th><th>Description</th></tr></thead><tbody><tr><td>_id</td><td>ObjectId</td><td>This is the unique identifier of the object.</td></tr><tr><td>name</td><td>string</td><td>Every Object name is unique in an organization. It should be in the camelCase format. We can use this name to get data from the object.</td></tr><tr><td>containsUsers</td><td>boolean</td><td>This is an optional attribute. However, if the objective is to store additional user information in an Object, then this value must be set to true. This will allow the user to create an Item in the object in which the _id will be the same as the logged-in user, thereby enforcing a one-to-one relationship between the ‘users’ collection in the auth database and the item collection of the object.</td></tr><tr><td>enableVersionHistory</td><td>boolean</td><td>When this optional field is set to true, the system generates a read-only array field named '_versionHistory' and a read-only string field named '_version' within each item of the Object. The '_version' field begins with '1.0' and increments by 0.1 with each update made to the item. As a result, the previous version of the item is added to the '_versionHistory', allowing users to track the changes made to it.</td></tr><tr><td>fields</td><td>ObjectArray</td><td>"The 'fields' attribute is an array that contains the definitions for all the fields associated with an object. These fields have common attributes such as _id, name, label, type, and validators. The _id and name is unique within an Object. In the case of a choice field, an additional attribute called 'options' is included, which is a string array that lists all the available options. For reference fields, there is an attribute called 'lookup', which will be further explained in the following section where all the different types of fields will be discussed."</td></tr><tr><td>_createdAt</td><td>Date</td><td>This is the date and time when the object was created.</td></tr><tr><td>_createdBy</td><td>string</td><td>This is the email of the user who created the object</td></tr><tr><td>_modifiedAt</td><td>Date</td><td>This is the date and time when the object was last modified</td></tr><tr><td>_modifiedBy</td><td>string</td><td>This is the email of the user who last modified the object.</td></tr><tr><td>_collectionName</td><td>string</td><td>This is the name of the item collection where the object data is stored. The item collection follows a specific syntax: <code>&#x3C;first_8_characters_of_object_name>_&#x3C;object_id></code></td></tr></tbody></table>

Below is a comprehensive list of field types supported by the Accelerator Platform, along with the validators applicable to each field type. Note that the data type refers to the value type of the field.

Common Validators:

1. isRequired: When set to true, this validator prohibits null or empty string values from being inserted or edited in the field of an object's item. This validator is applicable to all field types.
2. isUnique: When set to true, the value of the field must be unique in the object's item collection. this validator is applicable for text, number, date, and email fields.
3. regex: This validator is used to validate text and email fields using a regular expression.

{% embed url="<https://app.accelerator-platform.com/SampleFields.json>" %}
To see a list of sample field objects
{% endembed %}

{% embed url="<https://app.accelerator-platform.com/SampleItem.json>" %}
To see a list of sample item object
{% endembed %}

<table data-header-hidden><thead><tr><th width="123">Field Type</th><th width="114">Data Type</th><th width="137">Validators</th><th>Description</th></tr></thead><tbody><tr><td>text</td><td>string</td><td><p>isRequired,</p><p>isUnique,</p><p>regex,</p><p>minChars,</p><p>maxChars</p></td><td><p>To restrict the length of characters in a text field use ‘minChars’ and ‘maxChars’ validators.</p><p>Sample Field:<br>{</p><p>        "type": "text",</p><p>        "name": "name",</p><p>        "label": "Patient Name",</p><p>        "validators": {</p><p>            "isRequired": true,</p><p>            "minChars": 3,</p><p>            "maxChars": 50</p><p>        }</p><p>}</p></td></tr><tr><td>number</td><td>integer/double</td><td><p>isRequired,</p><p>isUnique,</p><p>regex,</p><p>min,</p><p>max,</p><p>isInteger</p></td><td><p>The number field is capable of storing rational numbers. To only allow integers, set the 'isInteger' to true. To limit the range of values for the number field, use the 'min' and 'max' validators.</p><p>Sample Field:</p><p>{</p><p>        "type": "number",</p><p>        "name": "contactNo",</p><p>        "label": "Patient Contact No",</p><p>        "validators": {</p><p>            "regex": "^[0-9]{10}$",</p><p>            "isRequired": true</p><p>        }</p><p>}</p></td></tr><tr><td>date</td><td>date</td><td><p>isRequired,</p><p>isUnique,</p><p>minDate,</p><p>maxDate</p></td><td><p>The date field accepts dates in a string format conforming to ISO 8601 standards. To define a date range, use the 'minDate' and 'maxDate' validators, which should be formatted in the same ISO 8601 format. Additionally, it is possible to set either value to 'Today' which will compare the date field value with the date and time when an item is being inserted or edited. For instance, if a date field stores a person's date and time of birth, the 'maxDate' validator can be set to 'Today' to ensure that the date and time of birth is not later than the date and time when the item is being inserted.<br>Sample FIelds:<br>{</p><p>        "type": "date",</p><p>        "name": "dob",</p><p>        "label": "Date of Birth",</p><p>        "validators": {</p><p>            "isRequired": true,</p><p>            "minDate": "1900-12-25",</p><p>            "maxDate": "Today"</p><p>        }</p><p>}</p></td></tr><tr><td>email</td><td>string</td><td><p>isRequired,</p><p>isUnique,</p><p>regex</p></td><td><p>Sample Field:<br>{</p><p>        "type": "email",</p><p>        "name": "email",</p><p>        "label": "Email",</p><p>        "validators": {</p><p>          "isRequired": true,</p><p>          "isUnique": true,</p><p>          "regex": "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"</p><p>        }</p><p>}</p></td></tr><tr><td>choice</td><td>string</td><td><p>isRequired,</p><p>isSingleChoice</p></td><td><p>When there is a need to store a selection of values from a range of options, a choice field can be used. For all choice fields, it is mandatory to provide the 'options' attribute, which is an array of strings that contains all the available options. To insert multiple values into this field, use a comma-separated string format such as "option1, option2, option3". Additionally, it is possible to apply the ‘isSingleChoice’ validator to only allow one option to be selected.</p><p>Sample Field:</p><p>{</p><p>        "type": "choice",</p><p>        "name": "gender",</p><p>        "label": "Gender",</p><p>        "options": [ "Male", "Female" ],</p><p>        "validators": {</p><p>            "isRequired": true,</p><p>            "IsSingleChoice": true</p><p>        }</p><p>}</p></td></tr><tr><td>file</td><td>string</td><td><p>isRequired,</p><p>maxFileSize,</p><p>minFileSize allowedFileTypes</p></td><td><p>To insert an item that contains a file field, a two-step process is required. First, the file(s) must be uploaded using the UploadFiles API endpoint, which returns a list of IDs of the uploaded files. These IDs can then be used as the file field value when inserting an item. To limit the file size, validators such as "maxFileSize" and "minFileSize" can be used, which accept file sizes in the format of 100.0 KB, 1.0 MB, or 1.0 GB. It’s also possible to allow only a certain types of files using the “allowedFileTypes” validator, accept an array of file extensions</p><p>e. g.  [  ".jpg", ".png", ".pdf" ].</p><p> </p><p>Sample Field:</p><p>    {</p><p>        "type": "file",</p><p>        "name": "profilePic",</p><p>        "label": "Upload a Profile Picture",</p><p>        "validators": {</p><p>            "isRequired": true,</p><p>            "minFileSize": "1.5 KB",</p><p>            "maxFileSize": "1.5 MB",</p><p>            "allowedFileTypes": [ "jpeg", "png", "jpg" ]</p><p>        }</p><p>    }</p></td></tr><tr><td>reference</td><td>string</td><td>isRequired</td><td><p>In the Accelerator Platform, a Reference field in an Object is capable of storing the '_id' of an Item from another Object within the same Organization. Whenever an Item with a reference field is retrieved, the '_id' allows the retrieval of additional information from the referenced Item. Therefore, the "lookup" attribute is mandatory for reference fields. This attribute is a JSON object that includes the "ObjectId" to hold the Id of the reference object and "returnedFields", an array of fields from the reference object that we want to retrieve when fetching the item.<br>Sample Field:</p><p>{</p><p>        "type": "reference",</p><p>        "name": "provider",</p><p>        "label": "Provider",</p><p>        "validators": {</p><p>            "isRequired": true</p><p>        },</p><p>        "lookup":{</p><p>            "ObjectId": "&#x3C;Providers-Object-Id>",</p><p>            "returnedFields": [ "name", "email" ]</p><p>        }</p><p>}<br>Sample Item:<br>{</p><p>       "provider": "&#x3C;Provider-Item-Id>"<br>}</p></td></tr><tr><td>array</td><td>JSON Array</td><td>isRequired</td><td><p>This Field is used to store JSON Array</p><p>Sample Field:<br>{</p><p>        "type": "array",</p><p>        "name": "symptoms",</p><p>        "label": "Symptoms"</p><p>}</p><p>Sample Item:<br>{<br>        "symptoms": [ "Fever", "Cough" ]</p><p>}</p></td></tr><tr><td>object</td><td>JSON Object</td><td>isRequired</td><td><p>This Field is used to store JSON Object<br>Sample Field:</p><p>{</p><p>        "type": "object",</p><p>        "name": "address",</p><p>        "label": "Address",</p><p>}</p><p>Sample Item:<br>{<br>    "address": {</p><p>         "addressLine": "Address Line ",  city": "City",   …   </p><p>    }<br>}</p></td></tr></tbody></table>

Field Level Encryption: To encrypt a Field's value, set the "isEncrypted" attribute to true. This will store the value in an unreadable format

```
// Sample Field:
{
        "type": "number",
        "name": "ssn",
        "label": " Social Security number ",
        " isEncrypted ":  true,
        "validators": {    "isRequired": true  }
}

```

Example 2:

Use-case: To understand the functionalities of the Accelerator Platform, We will be implementing the following use case.

1. We have a organization called Clinic.
2. There are two type of user Providers and Patients.
3. Providers can invite a Patients
4. After Register and Login, users can insert and update their personal information.
5. Providers can view only those Patients that they are associated with.
6. Patients can view all the Providers in the Clinic.

In Example 1, we created the organization. Now we are ready to create the Objects

Step2.  Create Provider Object

POST <https://qa.accelerator-platform.com/api/v1/CreateObject>

```
//   Request Header:
  {
    "Authorization": "bearer <Project-Admin-AuthToken>"
  }
  Request Body:
  {
    "name": "Providers",
    "containsUsers": true,
    "fields":[
      {
          "type": "text",
          "name": "name",
          "label": "Name",
          "validators": {
              "isRequired": true,
              "minChars": 3,
              "maxChars": 50
          }
      },
      {
          "type": "email",
          "name": "email",
          "label": "Email",
          "validators": {
            "isRequired": true,
            "isUnique": true,
            "regex": "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"
          }
      }
    ]
  }
  Response Body:
200
  <Providers-object-id>
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

Note that the containsUsers flag is set to true. Since Provider object will store Provider’s user information that may not be there in the users collection of the auth database.

Step 3. Create Patients Object\
POST <https://qa.accelerator-platform.com/api/v1/CreateObject>

```
//   Request Header:
  {
    "Authorization": "bearer <Project-Admin-AuthToken>"
  }
  Request Body:
  {
    "name": "Patients",
    "containsUsers": true,
    "fields":[
      {
          "type": "text",
          "name": "name",
          "label": "Name",
          "validators": {
              "isRequired": true,
              "minChars": 3,
              "maxChars": 50
          }
      },
      {
          "type": "email",
          "name": "email",
          "label": "Email",
          "validators": {
            "isRequired": true,
            "isUnique": true,
            "regex": "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"
          }
      },
      {
          "type": "reference",
          "name": "provider",
          "label": "Provider",
          "validators": {
              "isRequired": true
          },
          "lookup":{
              "ObjectId": "<Providers-object-Id>",
              "returnedFields": [
                  "name",
                  "email"
              ]
          }
      }
    ]
  }
  Response Body:
200
  <Patients-object-id>
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

Note: In the Patients object, there is a reference field.

Once the Objects have been created, the next step is to invite Users and create Policies and Roles. For more information on this topic, you can refer to the Accelerator Platform IAM Documentation by clicking on the link [here](https://touchcoresystems.sharepoint.com/:w:/s/TouchcoreAccelerator/Ee2s2Vkn4fBAqWVR4ONea90ByIf2hu_zXkmulm_GhJ-KjQ?e=DITJXB).

Step 4. Add Items to Object: After the Provider Registration and Login we are ready to insert Item into the Provider Object

POST [https://qa.accelerator-platform.com/api/v1/AddItems/Providers](https://qa.accelerator-platform.com/api/v1/GetItems/Providers)

```
// Request Header:
{
  "Authorization": "bearer <Provider -AuthToken>"
}
Request Body:
[
  {
    "name": "Ajay", 
    "email": "provider.ajay@gmail.com"
  }
]
Response:
200
<n> of <n> items inserted successfully
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

Please note that to create an item, the Object's name is utilized in the request URL, and the JSON object of the item is constructed using the field names of the Object. As the AddItems API endpoint receives a list of items, the JSON object is enclosed within a JSON list.

Step 5. Following is the request to get a list of all the Item\
GET <https://qa.accelerator-platform.com/api/v1/GetItems/Providers>

```
// 
{
  "Authorization": "bearer <Provider -AuthToken>"
}

```

Step 6. In the same way add Patients

POST <https://qa.accelerator-platform.com/api/v1/AddItems/Patients>

```
// Request Header:
{
  " Authorization ": "bearer <Patient-AuthToken>"
}
Request Body:
[
  {
    "name": "Lalit", 
    "email": "patient.lalit@gmail.com",
    "provider": "<provider-item-Id>"
  }
]
Response:
200
<n> of <n> items inserted successfully
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

Since the Patient Role has Policy that provide read access to “\_id”, “name”, and “email” fields of all the Providers, You can get a \<provider-item-id> by using the GetItems API endpoint with the Patient’s auth token

GET <https://qa.accelerator-platform.com/api/v1/GetItems/Providers>

```
// Request Header:
{
  "Authorization": "bearer <Patient-AuthToken>"
}
Response:
200
<Json-list-of-providers>
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

Following is the request to get a list of all the Patients\
POST <https://qa.accelerator-platform.com/api/v1/GetItems/Patients>

```
// Request Header:
{
  "Authentication": "bearer <Patient-AuthToken>"
}
Response:
200
<Json-list-of-patients>
400  
{  
 "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",  
 "title": "One or more validation errors occurred.",  
 "status": 400,  
 "traceId": "00-d8e7cef64a92d286849ae53583ab4775-c0cabf25d7ac41cb-00",  
 "errors": { ... }  
} 
401  
Unauthorized 
403 
Forbidden

```

As there is a reference to providers in Patients, In the response the provider field of the items should include the \_id, name, and email of the providers, where the \_id matches the "\<provider-item-Id>".

You can add more Providers and assign more Patients to them. Observe which Providers can access which Patients.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.accelerator-platform.com/accelerator-platform-core-apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
