# Branches

### GET /branches

Retrieve a list of branches

| Parameter | Type  | Required | Description                                    |
| --------- | ----- | -------- | ---------------------------------------------- |
| page      | query | No       | Number of the page returned. Default: 0        |
| limit     | query | No       | Items per page returned. Default: 10, Max: 100 |

#### Example <a href="#example" id="example"></a>

```
curl -X GET \
  'https://api.woowup.com/apiv3/branches?page=0&limit=1' \
  -H 'accept: application/json' \
  -H 'authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
  -H 'cache-control: no-cache'
```

#### Response <a href="#response" id="response"></a>

```
{
    "payload": [
        {
            "id": 1,
            "name": "Palermo I",
            "display_name": "Palermo",
            "description": "",
            "status": "active",
            "created": "2018-04-13 15:12:50",
            "modified": null,
            "holder": null,
            "email": null,
            "telephone": null,
            "address": null,
            "working_hours": null,
            "notes": null,
            "branch_zone_name": null
        }
    ],
    "message": "ok",
    "code": "ok",
    "time": "25ms"
}
```

#### HTTP Response codes <a href="#http-response-codes" id="http-response-codes"></a>

| HTTP Code | Name               | Description                                    |
| --------- | ------------------ | ---------------------------------------------- |
| 200       | ok                 | Successful request                             |
| 400       | bad request        | Invalid parameters                             |
| 403       | forbidden          | Invalid or inexistent apikey                   |
| 405       | method not allowed | Use an invalid http verb in the request        |
| 500       | server error       | Internal error, explained in the json response |

### GET /branches/{id}

Retrieve a specific branch identified by id.

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| id        | uri  | Yes      | Branch ID   |

#### Example <a href="#example-1" id="example-1"></a>

```
curl -X GET \
  'https://api.woowup.com/apiv3/branches/1' \
  -H 'accept: application/json' \
  -H 'authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
  -H 'cache-control: no-cache'
```

#### Response <a href="#response-1" id="response-1"></a>

```
{
    "payload": {
        "id": 1,
        "name": "Palermo I",
        "display_name": "Palermo",
        "description": "",
        "status": "active",
        "created": "2018-04-13 15:12:50",
        "modified": null,
        "holder": null,
        "email": null,
        "telephone": null,
        "address": null,
        "working_hours": null,
        "notes": null,
        "branch_zone_name": null
    },
    "message": "ok",
    "code": "ok",
    "time": "25ms"
}
```

#### HTTP Response codes <a href="#http-response-codes-1" id="http-response-codes-1"></a>

| HTTP Code | Name               | Description                                    |
| --------- | ------------------ | ---------------------------------------------- |
| 200       | ok                 | Successful request                             |
| 400       | bad request        | Invalid parameters                             |
| 403       | forbidden          | Invalid or inexistent apikey                   |
| 405       | method not allowed | Use an invalid http verb in the request        |
| 500       | server error       | Internal error, explained in the json response |

### POST /branches

Create a new branch.

The json with the branch should be valid with the following [json-schema](http://json-schema.org/)

**Request content format**

```
{
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "A branch",
        "type": "object",
        "required": ["name"],
        "properties": {
            "name": { "type": "string", "minLenght": 1, "maxLength": 128 },
            "description": { "type": ["string", "null"], "minLenght": 1, "maxLength": 100 },
            "display_name": { "type": ["string", "null"], "minLenght": 1, "maxLength": 128 },
            "email": { "type": ["string", "null"] },
            "telephone": { "type": ["string", "null"] },
            "address": { "type": ["string", "null"] },
            "working_hours": { "type": ["string", "null"] },
            "notes": { "type": ["string", "null"] },
            "branch_zone": {
                "type": ["object", "null"],
                "properties": {
                    "code": { "type": "string" },
                    "name": { "type": "string" }
                }
            },
            "holder": { "type": ["string", "null"] },
            "status": { "type": ["string", "null"], "enum": ["active", "inactive"] },
            "country": {
                "type": ["object", "null"],
                "properties": {
                    "code": { "type": "string" }
                }
            },
            "state": { "type": ["string", "null"] },
            "city": { "type": ["string", "null"] },
            "business_type": { "type": ["string", "null"], "enum": ["own", "franchisee", null] },
            "shopping_center": { "type": ["string", "null"] },
            "location_type": { "type": ["string", "null"] },
            "m2": { "type": ["integer", "null"] },
            "m2_cost": { "type": ["integer", "null"] },
            "employees_quantity": { "type": ["integer", "null"] },
            "group": { "type": ["string", "null"] },
            "format": { "type": ["string", "null"], "enum": ["brand_branch", "multibrand_branch", "brand_island", "multibrand_island", "outlet", null] },
            "is_web": { "type": "boolean" }
        }
    }
```

**Example**

This is a valid branch according to the previous [json-schema](http://json-schema.org/):

```
{
    "name" : 'Shopping de Prueba',
    "description" : "Este Shopping es una prueba para el endpoint de creación de sucursales",
    "working_hours" : "Lunes a Viernes 9.00 a 22.00 hs",
    "email" : "shopping@marca.com.ar",
    "telephone" : "01132392300",
    "holder" : "Gerente Juan Perez",
    "branch_zone_name" : "Buenos Aires",
    "country": ARG
}
```

**Errors**

| HttpCode | HttpCode Name  | Code            | Description                                       |
| -------- | -------------- | --------------- | ------------------------------------------------- |
| 201      | ok             | ok              | Branch successfully saved                         |
| 400      | bad request    | bad\_request    | Invalid parameters, view message for more details |
| 400      | bad request    | already\_exist  | The branch already exist                          |
| 500      | internal error | internal\_error | Unexpected error                                  |

### PUT /branches/{id}

Update a branch.

| Parameter | Type | Required | Description         |
| --------- | ---- | -------- | ------------------- |
| id        | URI  | Yes      | Branch Id in WoowUp |

The json with the branch should be valid with the following [json-schema](http://json-schema.org/)

**Request content format**

```
{
        "$schema": "http://json-schema.org/draft-04/schema#",
        "description": "A branch",
        "type": "object",
        "properties": {
            "name": { "type": "string", "minLenght": 1, "maxLength": 128 },
            "description": { "type": "string", "minLenght": 1, "maxLength": 100 },
            "display_name": { "type": ["string", "null"], "minLenght": 1, "maxLength": 128 },
            "email": { "type": "string" },
            "telephone": { "type": "string" },
            "address": { "type": "string" },
            "working_hours": { "type": "string" },
            "notes": { "type": "string" },
            "branch_zone_name": { "type": "string" },
            "holder": { "type": "string" },
            "status": { "type": "string", "enum": ["active", "inactive"] }
        }
    }
```

**Example**

This is a valid branch according to the previous [json-schema](http://json-schema.org/), We are going to change branch description, working hours and it's zoneN

```
{
    "description": "Este shopping es una prueba para el endpoint de actualización de sucursales",
    "working_hours": "Lunes a Viernes 11.00 a 22.00 hs",
    "branch_zone_name": "Pilar"
}
```

**Errors**

| HttpCode | HttpCode Name  | Code            | Description                                       |
| -------- | -------------- | --------------- | ------------------------------------------------- |
| 200      | ok             | ok              | Branch successfully updated                       |
| 400      | bad request    | bad\_request    | Invalid parameters, view message for more details |
| 404      | not found      | not\_found      | The branch doesn't exist                          |
| 500      | internal error | internal\_error | Unexpected error                                  |

## Delete branch

<mark style="color:red;">`DELETE`</mark> `https://api.woowup.com/apiv3/branches`

Delete a branch and its purchases

#### Request Body

| Name       | Type    | Description                       |
| ---------- | ------- | --------------------------------- |
| id         | integer | Branch Id in WoowUp               |
| notify\_to | string  | email to receive the confirmation |

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

```javascript
{
    "payload": {
        "request_id": "xxxx"
    },
    "message": "ok",
    "code": "ok",
    "time": "62ms"
}
```

{% endtab %}

{% tab title="400 " %}

```javascript
{
    "payload": {
        "errors": [
            "Required properties missing: [\"id\"]"
        ]
    },
    "message": "bad request",
    "code": "bad_request",
    "time": "240ms"
}
```

{% endtab %}

{% tab title="403 " %}

```javascript
{
    "payload": [],
    "message": "forbidden: authentication failed",
    "code": "forbidden",
    "time": "7ms"
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
    "payload": {
        "errors": "The branch doesn't exist"
    },
    "message": "not found",
    "code": "not_found",
    "time": "891ms"
}
```

{% endtab %}

{% tab title="500 " %}

```javascript
{
    "payload": [],
    "message": "",
    "code": "internal_error",
    "time": "72ms"
}
```

{% endtab %}
{% endtabs %}

**Example**

```bash
curl -X DELETE \
  https://api.woowup.com/apiv3/branches \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic XXXXXXXXXXXXXXXXXXXX' \
  -H 'Content-Type: application/json' \
  -d '{
	"id": 00000,
	"notify_to": "test@email.com"
}'
```

**Response**

```javascript
{
    "payload": {
        "request_id": "XXXX"
    },
    "message": "ok",
    "code": "ok",
    "time": "62ms"
}
```
