# Project

Any experience is called a "project" in the GMetri SDK.&#x20;

The field you are most interested in is the "json" field, which is an object of type `RecordNode<RT.project>`&#x20;

Changes to the project body (`project.json`) can be sent in via the updateJSON API which takes in the whole json at once or the applyJSONPatches which allows you send in an array of diffs.

In case you send patches, they need to be an array of type "JSON patches" <https://immerjs.github.io/immer/patches/>

<details>

<summary>Project Schema</summary>

* **id**: Unique id for every project
* **uuid**: Unique string identifier for every project (UUID format)
* **name**: Name of the project (has to be unique for per workspace for every project)
* **thumbnail**: The thumbnail URL
* **created\_at**: Create at timestamp
* **modified\_at**: Modified at timestamp
* **organization\_id**: Unique id of the organization this project belongs to
* **json**: the body of the project. Of type `RecordNode<RT.project>`&#x20;

</details>

## Create Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/create`

Create new project with default JSON.

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                      | Type   | Description                                      |
| ----------------------------------------- | ------ | ------------------------------------------------ |
| name<mark style="color:red;">\*</mark>    | String | The name of project                              |
| orgSlug<mark style="color:red;">\*</mark> | String | The unique identification string of organization |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    },
    "data": {
        "id": 37,
        "name": "Mitul Test",
        "uuid": "9ead035f-1ec4-45c8-9fcc-2aaedfc8c4f8",
        "thumbnail": null,
        "created_at": "2022-10-20T18:07:14.193625",
        "modified_at": "2022-10-20T18:07:14.193625",
        "organization_id": 6
    }
}
```

{% endtab %}
{% endtabs %}

## Get Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/get`

Get the project using project uuid

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                       | Type   | Description                                    |
| ------------------------------------------ | ------ | ---------------------------------------------- |
| projUuid<mark style="color:red;">\*</mark> | String | Unique identifier of the project (UUID format) |

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
    "status": {
        "success": true
    },
    "data": {
        "id": 33,
        "name": "test7 (1)",
        "uuid": "6ee092d0-bc12-4c89-8d75-05ba9ea50218",
        "thumbnail": "https://s.vrgmetri.com/image/w_400,q_90/gb-web/r3f-ui/assets/pano/0_grid_02_white.jpg",
        "created_at": "2022-10-19T09:24:32.20418",
        "modified_at": "2022-10-19T09:25:10.131",
        "organization_id": 6
    }
}
```

{% endtab %}

{% tab title="401: Unauthorized When no Authorization header attached" %}

```javascript
{
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "Error from z5api: No Authorization was found in request.headers"
}
```

{% endtab %}

{% tab title="200: OK Failure" %}

```javascript
{
    "status": {
        "success": false,
        "errorMessage": "Opps! Something went wrong. Please try again later."
    }
}
```

{% endtab %}
{% endtabs %}

## Get All Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/getAll`

Get all project for the orgnization

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                      | Type   | Description                                                                 |
| ----------------------------------------- | ------ | --------------------------------------------------------------------------- |
| orgSlug<mark style="color:red;">\*</mark> | String |                                                                             |
| searchString                              | String | Search project by name                                                      |
| sortKey<mark style="color:red;">\*</mark> | String | Get project by sorted order by \["modified\_at" \| "created\_at" \| "name"] |
| orderBy<mark style="color:red;">\*</mark> | String | "ASC" \| "DESC"                                                             |
| limit<mark style="color:red;">\*</mark>   | String | No of records                                                               |
| offset<mark style="color:red;">\*</mark>  | String | Next page offset to support pagination                                      |

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
    "status": {
        "success": true
    },
    "data": {
        "projects": [
            {
                "id": 35,
                "name": "test7 (3)",
                "uuid": "b1e9360e-86bb-4a79-879a-02041a325d9a",
                "thumbnail": "https://s.vrgmetri.com/image/w_400,q_90/gb-web/r3f-ui/assets/pano/0_grid_02_white.jpg",
                "created_at": "2022-10-19T19:59:27.898471",
                "modified_at": "2022-10-19T19:59:27.988",
                "organization_id": 6
            },
            {
                "id": 34,
                "name": "test7 (2)",
                "uuid": "abd7409f-58f2-4fca-813b-761a47d47092",
                "thumbnail": "https://s.vrgmetri.com/image/w_400,q_90/gb-web/r3f-ui/assets/pano/0_grid_02_white.jpg",
                "created_at": "2022-10-19T09:25:24.306648",
                "modified_at": "2022-10-19T09:25:24.376",
                "organization_id": 6
            }
        ],
        "totalCount": 21
    }
}
```

{% endtab %}
{% endtabs %}

## Update Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/update`

Update project name or tag by project uuid

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                       | Type            | Description      |
| ------------------------------------------ | --------------- | ---------------- |
| projUuid<mark style="color:red;">\*</mark> | String          |                  |
| name                                       | String          | Project new name |
| tags                                       | Array of String | Project tag      |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    },
    "data": {
        "id": 21,
        "name": "mitul test",
        "uuid": "39be32c8-0415-4b27-9667-d983de4fc07b",
        "thumbnail": "https://s.vrgmetri.com/image/w_400,q_90/gb-web/r3f-ui/assets/pano/0_grid_02_white.jpg",
        "created_at": "2022-09-22T18:47:38.708681",
        "modified_at": "2022-10-20T09:13:02.826",
        "organization_id": 6
    }
}
```

{% endtab %}
{% endtabs %}

## Delete Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/delete`

Delete project by project uuid

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| projUuid<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    }
}
```

{% endtab %}
{% endtabs %}

## Get Project JSON

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/getJSON`

Get Project JSON by project uuid

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| projUuid<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{​
  "status": {​
    "success": true,​
    "errorCode": "string",​
    "errorMessage": "string"​
  },​
  "data": RecordNode<RT.project> //project's rJSON​
​}
```

{% endtab %}
{% endtabs %}

## Update JSON

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/updateJSON`

Update project json(RecordNode\<RT.project>) by project uuid

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Token \<apiToken> |

#### Request Body

| Name                                       | Type   | Description                                  |
| ------------------------------------------ | ------ | -------------------------------------------- |
| projUuid<mark style="color:red;">\*</mark> | String |                                              |
| json<mark style="color:red;">\*</mark>     | Object | rJSON of the project RecordNode\<RT.project> |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    }
}
```

{% endtab %}
{% endtabs %}

## Apply JSON Patches

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/applyJSONPatches`

Apply JSON patches and by getting diff JSON and update new JSON by project uuid

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                       | Type   | Description                                             |
| ------------------------------------------ | ------ | ------------------------------------------------------- |
| projUuid<mark style="color:red;">\*</mark> | String |                                                         |
| patches<mark style="color:red;">\*</mark>  | Object | JSON patches <https://immerjs.github.io/immer/patches/> |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    }
}
```

{% endtab %}
{% endtabs %}

## Duplicate Project

<mark style="color:green;">`POST`</mark> `https://api.gmetri.com/sdk/project/duplicate`

Make copy of project inside same organization

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| projUuid<mark style="color:red;">\*</mark> | String |             |
| orgSlug<mark style="color:red;">\*</mark>  | String |             |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": {
        "success": true
    },
    "data": {
        "projectUuid": "b1e9360e-86bb-4a79-879a-02041a325d9a" // copy project uuid
    }
}
```

{% endtab %}
{% endtabs %}
