# Create Custom Entity Record

This tutorial should help you create the first Custom Entity record. Before moving forward, make sure your [**Authentication** ](https://developers.pipelinersales.com/api-docs/overview/authentication)works and you understand the [**Key Concepts**](https://developers.pipelinersales.com/api-docs/core-api-concepts/understanding-the-crm-concept) of the Pipeliner API and make sure you know how to use [**API parameters**](https://developers.pipelinersales.com/api-docs/core-api-concepts/api-parameters)

**The Custom Entity** allows user to work with a completely new type of entity in Pipeliner. You can create Custom Entity records and link them with other entities using Lookup fields.

## Tutorial Assignment

* Create Custom Entity record with the particular Entity Type&#x20;
* Link Custom Entity record to Opportunity using Lookup field
* Filter existing Custom entity record by custom field

### 0.  Required fields

<table><thead><tr><th width="308.2672043757614">Required API field Name</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>Name of the custom entity record</td></tr><tr><td>owner_id</td><td>Id of the User in Pipeliner Application</td></tr><tr><td>type_id</td><td>Id of the related Custom Entity Expected Closing date.</td></tr></tbody></table>

### 1.  Prepare Data

#### Owner\_id

Load an id of the user with the [default sales unit](https://developers.pipelinersales.com/api-docs/core-api-concepts/understanding-the-crm-concept#users-and-roles-and-sales-units-accessing-records). This user will become the owner of the newly created Custom Entity Record.

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FOlNVdYj1h5GSxQmLHAjz%2Fopenapi%20(1).json?alt=media&token=4be07353-5170-4a95-9100-4f16545d47b0>" path="/entities/Clients" method="get" %}
[openapi (1).json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FOlNVdYj1h5GSxQmLHAjz%2Fopenapi%20\(1\).json?alt=media\&token=4be07353-5170-4a95-9100-4f16545d47b0)
{% endopenapi %}

```
{{baseUrl}}/entities/Clients?load-only=id,default_unit_id&filter[email]=john.doe@example.com
```

```json
{
            "id": "00000000-0000-0000-0000-000000011a7d",
            "default_unit_id": "aba4a358-f3f8-4f55-b3ed-dd5cf589103b"
}
```

{% hint style="info" %}
We don´t necessarily need to load the default unit id. If only owner\_id is specified in the final request, Pipeliner will automatically create the opportunity with the default User´s sales unit.  (See step 2. of this tutorial)
{% endhint %}

#### Type\_id

Pull Custom Entity Types. Store the ID of the Custom Entity Type

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b>" path="/entities/{custom\_entity\_api\_name}Type" method="get" %}
[openapi\_2023\_09\_27\_3.json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media\&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b)
{% endopenapi %}

```
{{baseUrl}}/entities/MyCustomEntityType
```

```json
 
{
	"is_delete_protected": true,
	"has_draft": false,
	"id": "00000000-0000-0000-0000-000000000002",
	"is_deleted": false,
	"modified": "2023-09-20 07:08:32.528011+00:00",
	"created": "2023-09-11 08:38:36.498033+00:00",
	"form_edit": {
	},
	"form_edit_api": {
	},
	"is_readonly": false,
	"name": "Custom entity 1",
	"is_published": true,
	"revision": 4288,
	"entity_api_name": "MyCustomEntity"
},
{
	"is_delete_protected": false,
	"has_draft": false,
	"id": "018ad56d-879c-b0dd-3c3a-75c59ab97a23",
	"is_deleted": false,
	"modified": "2023-09-27 06:57:23.126262+00:00",
	"created": "2023-09-27 06:57:19.772625+00:00",
	"form_edit": "",
	"form_edit_api": {
	},
	"is_readonly": false,
	"name": "Custom entity 2",
	"is_published": true,
	"revision": 4461,
	"entity_api_name": "MyCustomEntity"
}
```

### 2. Create Custom Entity record

Let´s Take data from Step 1. and use them in the following request to create a Custom Entity record.

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b>" path="/entities/{custom\_entity\_api\_name}" method="post" %}
[openapi\_2023\_09\_27\_3.json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media\&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b)
{% endopenapi %}

```json
{
	"name": "Custom Entity Record 3",
	"owner_id": "00000000-0000-0000-0000-000000011a7d",
	"type_id": "018ad56d-879c-b0dd-3c3a-75c59ab97a23"
}
```

Success response

```json
{
	"success": true,
	"data": {
		"is_delete_protected": false,
		"id": "018ad5a4-2ea8-75f0-e8cc-c6e54688b165",
		"modified": "2023-09-27 07:57:01.480723+00:00",
		"created": "2023-09-27 07:57:01.480781+00:00",
		"owner": "http://example.com",
		"type": "http://example.com",
		"unit": "http://example.com",
		"name": "Custom Entity Record 3",
		"owner_id": "00000000-0000-0000-0000-000000011a7d",
		"share_mode": 0,
		"table_name": "ce_custom_entity1n",
		"type_id": "018ad56d-879c-b0dd-3c3a-75c59ab97a23",
		"unit_id": "7d9467e0-d885-4729-877e-5c9e1e057b4a",
		"is_deleted": false,
		"sharing_units": [],
		"sharing_clients": [],
		"documents": [],
		"is_favorite": false,
		"revision": 4464,
		"cf_high_priority": true,
		"cf_lookup_ce_mycustomentity_leadoppty": []
	}
}
```

### 3. Link Custom Entity record to existing record using Lookup field

Take data from Step 2. and use them in the following request, to link existing record to Opportunity using a Lookup field.

#### Get Opportunity\_id

We are going to search for Opportunity by name. But you can use whatever parameter.

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b>" path="/entities/Opportunities" method="get" %}
[openapi\_2023\_09\_27\_3.json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media\&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b)
{% endopenapi %}

```
{{baseUrl}}/entities/Opportunities?filter-op[name]=contains&filter[name]=Accounting
```

```json
{
        "is_delete_protected": false,
        "id": "0188d953-0aa6-1094-f764-1ce141993b26",
        "is_deleted": false,
        "modified": "2023-06-20 15:01:18.162394+00:00",
        "created": "2023-06-20 15:01:18.118462+00:00",
        "active_quote": null,
        "oppty_type": "http://example.com",
        "owner": "http://example.com",
        "product_currency": "http://example.com",
        "product_price_list": null,
        "reason_of_close": null,
        "step": "http://example.com",
        "unit": "http://example.com",
        "active_quote_id": null,
        "closing_date": "2023-06-21",
        "description": "",
        "is_archived": false,
        "is_value_auto_calculate": false,
        "label_flag": 0,
        "name": "Double Entry Accounting Services",
        "oppty_type_id": "0c03f112-4544-06a8-b162-1f14524c149c",
        "owner_id": "00000000-0000-0000-0000-000000011a7d",
        "product_currency_id": "c4ca4238-a0b9-0382-0dcc-509a6f75849b",
        "ranking": 50,
        "reason_of_close_description": "",
        "reason_of_close_id": null,
        "share_mode": 0,
        "step_id": "5854307d-d86e-4b97-be3f-a2c19f85ff07",
        "table_name": "oppty",
        "unit_id": "7d9467e0-d885-4729-877e-5c9e1e057b4a",
        "was_qualified": false,
        "revision": 3584,
        "value": {
        "base_value": 10000,
        "currency_id": "36665823-00d8-401f-b7d2-8e0736c3beb2",
        "value_foreign": 12500
        },
        "oppty_recurrence": null,
        "revenue_schedule": null,
        "product_relations": [],
        "primary_contact": null,
        "primary_account": "http://example.com",
        "contact_relations": [],
        "account_relations": [
                "http://example.com"
        ],
        "documents": [],
        "quote_relations": [],
        "status": 1,
        "qualify_date": null,
        "won_date": null,
        "lost_date": null,
        "days_in_step": 68,
        "is_favorite": false,
        "sharing_units": [],
        "sharing_clients": [],
        "tags": [],
        "formatted_name": "Double Entry Accounting Services",
        "modified_by_user": null
}
```

**Create a linking between Custom Entity record and Opportunity**

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b>" path="/entities/{custom\_entity\_api\_name}/{id}" method="patch" %}
[openapi\_2023\_09\_27\_3.json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media\&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b)
{% endopenapi %}

```json
{
	"cf_lookup_ce_mycustomentity_leadoppty": "0188d953-0aa6-1094-f764-1ce141993b26"
}
```

Success response

```json
{
		"is_delete_protected": false,
		"id": "018ad5a4-2ea8-75f0-e8cc-c6e54688b165",
		"modified": "2023-09-27 07:57:01.480723+00:00",
		"created": "2023-09-27 07:57:01.480781+00:00",
		"owner": "http://example.com",
		"type": "http://example.com",
		"unit": "http://example.com",
		"name": "Custom Entity Record 3",
		"owner_id": "00000000-0000-0000-0000-000000011a7d",
		"share_mode": 0,
		"table_name": "ce_custom_entity1n",
		"type_id": "018ad56d-879c-b0dd-3c3a-75c59ab97a23",
		"unit_id": "7d9467e0-d885-4729-877e-5c9e1e057b4a",
		"is_deleted": false,
		"sharing_units": [],
		"sharing_clients": [],
		"documents": [],
		"is_favorite": false,
		"revision": 4464,
		"cf_priority": 2,
		"cf_lookup_ce_mycustomentity_leadoppty": [
				"id": "0188d953-0aa6-1094-f764-1ce141993b26",
				"name": "Double Entry Accounting Services",
				"picture_url": null,
				"entity_name": "Opportunity",
				"entity_api_name": null,
				"entity_type_id": null,
				"is_deleted": false,
				"is_available": true
		]
}
```

### 4. Filter existing Custom Entity record by custom field

Filter Custom Entity records using the specific conditions.

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b>" path="/entities/{custom\_entity\_api\_name}" method="get" %}
[openapi\_2023\_09\_27\_3.json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FLAy3xMsdxwYMX3PYxYuJ%2Fopenapi_2023_09_27_3.json?alt=media\&token=2b57d3c5-14b3-4807-9ee6-98eb2dec651b)
{% endopenapi %}

```json
{{baseUrl}}/entities/MyCustomEntity?filter-op[cf_priority]=gt&filter[cf_priority]=3
```

Success response

```json
{
		"is_delete_protected": false,
		"id": "012bc5a7-23e8-15a0-a51b-e6c5462eb415",
		"modified": "2023-09-27 07:32:01.480723+00:00",
		"created": "2023-09-27 07:32:01.480781+00:00",
		"owner": "http://example.com",
		"type": "http://example.com",
		"unit": "http://example.com",
		"name": "Custom Entity Record 1",
		"owner_id": "00000000-0000-0000-0000-000000011a7d",
		"share_mode": 0,
		"table_name": "ce_custom_entity1n",
		"type_id": "018ad56d-879c-b0dd-3c3a-75c59ab97a23",
		"unit_id": "7d9467e0-d885-4729-877e-5c9e1e057b4a",
		"is_deleted": false,
		"sharing_units": [],
		"sharing_clients": [],
		"documents": [],
		"is_favorite": false,
		"revision": 4364,
		"cf_priority": 4,
		"cf_lookup_ce_mycustomentity_leadoppty": []
}
```
