# Contacts

### Contacts#index

Retrieves all firm contacts

```
GET /contacts
```

| parameter | values                    |
| --------- | ------------------------- |
| type      | 'Person' or 'Institution' |
| filter    | 'all'                     |

**Response:**

Returns a 200 OK with an array of contacts:

```
[
    {
        "id": 1,
        "first_name": "John",
        "last_name": "Doe",
        "middle_name": null,
        "company_name": "",
        "email": null,
        "lead": false,
        "lead_phone": null,        
        "created_at": "2020-04-02T23:49:19.738-05:00",
        "updated_at": "2020-04-02T23:49:20.403-05:00",
        "physical_address": {
            "id": null,
            "street_number_and_name": null,
            "apartment_number": null,
            "city": null,
            "state": null,
            "county": null,
            "province": null,
            "date_from": null,
            "date_to": null,
            "in_care_of": null,
            "created_at": null,
            "updated_at": null,
            "country": null
        }
    }
]
```

### Contacts#show

Returns a single contact

```
GET /contacts/:id
```

**Response:**

Returns a 200 OK with a single contact:

```
{
    "id": 1,
    "first_name": "John",
    "last_name": "Doe",
    "middle_name": null,
    "company_name": "",
    "email": null,
    "lead": false,
    "lead_phone": null,
    "created_at": "2020-04-02T23:49:19.738-05:00",
    "updated_at": "2020-04-02T23:49:20.403-05:00",
    "physical_address": {
        "id": null,
        "street_number_and_name": null,
        "apartment_number": null,
        "city": null,
        "state": null,
        "county": null,
        "province": null,
        "date_from": null,
        "date_to": null,
        "in_care_of": null,
        "created_at": null,
        "updated_at": null,
        "country": null
    },
    "notes": [
        {
            "id": 1,
            "content": "Note content",
            "category": "All Notes",
            "firm_id": 1,
            "matter_id": 1,
            "assignee_id": null,
            "created_at": "2024-12-04T16:40:14.026Z",
            "updated_at": "2024-12-04T16:40:14.026Z",
            "created_by_id": 1,
            "client_id": 1,
            "created_by_migration": null,
            "title": "Note Title",
            "date": "2024-12-04T16:39:00.000Z",
            "discarded_at": null,
            "starred": false,
            "author_name": null,
            "note_category_id": null
        }
    ]
}
```

### Contacts#**create**

Creates a new contact. Keep in mind to send contact data inside a contact root key.&#x20;

```
POST /contacts
```

You should pass a JSON with the following parameters:

* `first_name string`
* `middle_name string`
* `last_name string`
* `email string`
* `type 'Person' or 'Institution'`
* `lead boolean`
* `addresses_attributes array`
  * `data object`
    * `street_number_and_name string`
    * `apartment_number string`
    * `city string`
    * `state string`
    * `province string`
    * `zip_code string`
    * `physical boolean`
    * `mailing boolean`
* `phone_numbers_attributes`
  * `data`
    * `number string`
    * `daytime boolean`

```
{
	"contact": {
		"first_name": "Test",
		"middle_name": "Test",
		"last_name": "Test",
		"email": "test@test.com",
		"type": "Person",
		"addresses_attributes": [{
			"data": {
				"street_number_and_name": "This is and address",		 
				"physical": true
			}
		}],
		"phone_numbers_attributes": [{
			"data": {
				"number": "1234567",
				"daytime": true
			}
		}]
	}
}
```

**Response:**

Returns a 201 created.&#x20;

### Contacts#update

Updates an existing contact.&#x20;

```
PUT /contacts/:id
```

You should pass a JSON with the following parameters:

* `first_name string`
* `middle_name string`
* `last_name string`
* `company_name string`
* `type 'Person' or 'Institution'`
* `email string`
* `lead boolean`
* `addresses_attributes array`
  * `data object`
    * `id integer`
    * `street_number_and_name string`
    * `apartment_number string`
    * `city string`
    * `state string`
    * `province string`
    * `zip_code string`
    * `physical boolean`
* `phone_numbers_attributes`
  * `data`
    * `id integer`
    * `number string`
    * `daytime boolean`

```
{
	"contact": {
		"company_name": "Company Name",
		"type": "Institution",
		"addresses_attributes": [{
			"data": {
				"id": 1,
				"street_number_and_name": "This is and address",				 
				"physical": true
			}
		}],
		"phone_numbers_attributes": [{
			"data": {
				"id": "1",
				"number": "1234567",
				"daytime": true
			}
		}]
	}
}
```

**Response:**

Returns 200 OK

### Contacts#destroy

Destroys an existing contact

```
DELETE /contacts/:id
```

**Response:**

Returns 200 OK
