# Vendor Authentication

```
STAGING_URL: https://switch-api-staging.herokuapp.com
LIVE_URL: https://switchapi.azurewebsites.net
```

## Create Vendor&#x20;

<mark style="color:green;">`POST`</mark> `https://switch-api-staging.herokuapp.com/vendor/register`

This endpoint registers a Vendor and returns a valid token for sessions .

#### Request Body

| Name     | Type   | Description                  |
| -------- | ------ | ---------------------------- |
| category | string | vendor category              |
| name     | string | Name of Vendor               |
| email    | string | email of vendor              |
| password | string | preferred password of Vendor |

{% tabs %}
{% tab title="200 Cake successfully retrieved." %}

```javascript
{
    "message": "Vendor created successfully",
    "data": {
        "id": 197,
        "email": "example@gmail.com"
    }
}
```

{% endtab %}

{% tab title="404 Error" %}

```javascript
{
    "message": "Error occurred creating vendor",
    "errors": {
        "email": [
            "can't be blank"
        ],
        "password": [
            "can't be blank"
        ],
        "name": [
            "can't be blank"
        ],
        "category": [
            "can't be blank"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Login Vendor

<mark style="color:green;">`POST`</mark> `https://switch-api-staging.herokuapp.com/vendor/login`

This endpoint authenticate the vendor and returns a token used for sessions

#### Request Body

| Name     | Type   | Description     |
| -------- | ------ | --------------- |
| password | string | Vendor password |
| email    | string | vendor email    |

{% tabs %}
{% tab title="200 Vendor login successfully" %}

```
{
    "message": "Vendor login successful",
    "data": {
        "auth_token": "eyJhbGciOiJIUzI1NiJ9.eyJ2ZW5kb3JfaWQiOjcsImV4cCI6MTU0NzUyMjkyMSwiY29udGV4dCI6InZlbmRvciJ9.arMSfaN1eCcn5G47NBdUAwagKgNzERhUQaGvuhVE-JY",
        "vendor": {
            "id": 7,
            "email": "example@gmail.com"
        }
    }
}
```

{% endtab %}
{% endtabs %}

## Forgot Password

<mark style="color:green;">`POST`</mark> `https://switch-api-staging.herokuapp.com/vendor/forgot_password`

#### Request Body

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| email | string |             |

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

```
{
    "message": "Password reset email sent successfully"
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Email is invalid"
}
```

{% endtab %}
{% endtabs %}

## Reset Password

<mark style="color:blue;">`GET`</mark> `https://switch-api-staging.herokuapp.com/vendor/reset_password`

#### Path Parameters

| Name                   | Type   | Description                  |
| ---------------------- | ------ | ---------------------------- |
| reset\_password\_token | string | token attached to reset link |

#### Request Body

| Name     | Type   | Description             |
| -------- | ------ | ----------------------- |
| password | string | new password for vendor |

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

```
{
    "message": "Password changed successfully"
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Password could not be updated",
    "errors": {
        "reset_password_token": [
            "can't be blank"
        ]
    }
}
```

{% endtab %}
{% endtabs %}
