# Product Variants

{% hint style="info" %}
Because we are dealing with 2 IDs, we will be using <mark style="color:red;">`id`</mark> for the <mark style="background-color:yellow;">product</mark> ID and <mark style="color:purple;">`vid`</mark> for the <mark style="color:green;">variant</mark> ID
{% endhint %}

### Supported Endpoints

* `getAllVariants()`: Returns a list of all products created.
* `getVariant(id, vid)`: Gets listing by the entered ID.
* `createProductVariant(id, fields)`: Create Listing.
* `updateProductVariant(id, vid, fields)`: Updates a listing by the entered ID.
* `deleteProductVariant(id, vid)`: Deletes a listing by the entered ID.

***

### `getAllVariants()`

|   Parameters   |   Type  | Required |                  Description                  |
| :------------: | :-----: | :------: | :-------------------------------------------: |
|      `id`      |  string |    ✔️    |                ID of a Product                |
|     `limit`    | integer |     ❌    |     Limit the number of products returned     |
|     `page`     | integer |     ❌    | The page number you are attempting to access. |
| `with_trashed` | boolean |     ❌    |    Include deleted products in the results    |
|  `only_trash`  | boolean |     ❌    |   Limit the results to only deleted products  |

<details>

<summary>Usage</summary>

```javascript
const Sellapp = require("sellapp-node");
const API = new Sellapp.API("YOUR_API_KEY");

API.variants.getAllVariants().then((res) => {
    console.log(res)
});
```

</details>

***

### `getVariant()`

<table><thead><tr><th align="center">Parameters</th><th width="133" align="center">Type</th><th width="145" align="center">Required</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center"><code>id</code></td><td align="center">string</td><td align="center">✔️</td><td align="center">ID of a Product</td></tr><tr><td align="center"><code>vid</code></td><td align="center">string</td><td align="center">✔️</td><td align="center">ID of the Variant</td></tr></tbody></table>

<details>

<summary>Usage</summary>

```javascript
const Sellapp = require("sellapp-node");
const API = new Sellapp.API("YOUR_API_KEY");

API.variants.getProduct("6666", "565").then((res) => {
    console.log(res)
})
```

</details>

***

### `createProductVariant()`

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

|  Parameters  |  Type  | Required |    Description    |
| :----------: | :----: | :------: | :---------------: |
|     `id`     | string |    ✔️    | ID of the product |
|   `fields`   | object |    ✔️    |  Product's field  |
| {% endtab %} |        |          |                   |

{% tab title="Fields' Value" %}

|        Fields' Values       |       Type      | Required |                                                                    Description                                                                    |
| :-------------------------: | :-------------: | :------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: |
|           `title`           |      string     |    ✔️    |                                                                The product's title.                                                               |
|        `description`        |      string     |    ✔️    |                                                             The product's description.                                                            |
|           `image`           |   object/null   |     ❌    |                                       An image binary which will be visible when someone views your product.                                      |
|           `order`           |     int/null    |     ❌    |                                           The product's order in which it is sorted on your storefront.                                           |
|         `visibility`        |      string     |    ✔️    |                        Either "PUBLIC", "HIDDEN", or "PRIVATE" - depending on whether you want this product to be visible.                        |
|        `deliverable`        |      object     |    ✔️    | The product's deliverable which will be sent to the customer. Consists of three pieces of nested data, being "delivery\_text", "type", and "data" |
|           `price`           |      object     |    ✔️    |                         The product's price in nested format. Consists of two variables "PRICE" (in cents) and "CURRENCY".                        |
|           `humble`          |     boolean     |     ❌    |                              Whether you want to allow the customer to pay more than the product's price. ( ͡° ͜ʖ ͡°)                             |
|      `payment_methods`      | array of string |    ✔️    |                         Items Enum: "COINBASE" "PAYDASH" "PAYPAL" "STRIPE". The product's payment methods in array format.                        |
|   `additional_information`  |      array      |     ❌    |                                Additional info that can be requested from the customer during the checkout process.                               |
|       `bulk_discount`       |      array      |     ❌    |                                  An array of discounts when a customer purchases more than a specified quantity.                                  |
| `minimum_purchase_quantity` |       int       |    ✔️    |                                                 The minimum amount a customer is able to purchase.                                                |
| `maximum_purchase_quantity` |     int/null    |     ❌    |                                                 The maximum amount a customer is able to purchase.                                                |
|          `webhook`          |   string/null   |     ❌    |                                          A webhook URL that will receive updates when orders are placed.                                          |
|          `warranty`         |   object/null   |     ❌    |                                         The warranty time in which a customer is able to request a refund.                                        |
|           `locked`          |     boolean     |     ❌    |                                            Whether this product is locked by the admins or moderators.                                            |
|          `section`          |     int/null    |     ❌    |                              The ID of a section to associate with this product. Use null to disassociate a section.                              |
|            label            |   object/null   |     ❌    |                           The name of the additional information input. Examples: `TEXT`,`NUMBER`,`HIDDEN` ,`TEXTAREA` ,                          |
|         {% endtab %}        |                 |          |                                                                                                                                                   |
|        {% endtabs %}        |                 |          |                                                                                                                                                   |

<details>

<summary>Usage</summary>

```javascript
const Sellapp = require("sellapp-node");
const API = new Sellapp.API("YOUR_API_KEY");

API.variants.createProductVariant({
	"title": "Millions of gold pieces",
	"description": "Get rich, buy this.",
	"deliverable": {
		"delivery_text": "Meet me in world 5",
		"type": "MANUAL",
		"data": {
			"stock": 666,
			"comment": "Thanks"
		}
	},
	"price": {
		"price": 50,
		"currency": "USD"
	},
	"payment_methods": ["PAYPAL"],
	"minimum_purchase_quantity": 1,
	"visibility": "HIDDEN"
}).then((res) => {
    console.log(res);
}).catch((err) => {
    console.log(err);
});
```

</details>

***

### `updateProductVariant()`

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

|  Parameters  |  Type  | Required |              Description             |
| :----------: | :----: | :------: | :----------------------------------: |
|     `id`     | string |    ✔️    | ID of the product you want to update |
|   `fields`   | object |    ✔️    |            Product's field           |
| {% endtab %} |        |          |                                      |

{% tab title="Fields' Value" %}

|        Fields' Values       |       Type      | Required |                                                                    Description                                                                    |
| :-------------------------: | :-------------: | :------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: |
|           `title`           |      string     |    ✔️    |                                                                The product's title.                                                               |
|        `description`        |      string     |    ✔️    |                                                             The product's description.                                                            |
|           `image`           |   object/null   |     ❌    |                                       An image binary which will be visible when someone views your product.                                      |
|           `order`           |     int/null    |     ❌    |                                           The product's order in which it is sorted on your storefront.                                           |
|         `visibility`        |      string     |    ✔️    |                        Either "PUBLIC", "HIDDEN", or "PRIVATE" - depending on whether you want this product to be visible.                        |
|        `deliverable`        |      object     |    ✔️    | The product's deliverable which will be sent to the customer. Consists of three pieces of nested data, being "delivery\_text", "type", and "data" |
|           `price`           |      object     |    ✔️    |                         The product's price in nested format. Consists of two variables "PRICE" (in cents) and "CURRENCY".                        |
|           `humble`          |     boolean     |     ❌    |                              Whether you want to allow the customer to pay more than the product's price. ( ͡° ͜ʖ ͡°)                             |
|      `payment_methods`      | array of string |    ✔️    |                         Items Enum: "COINBASE" "PAYDASH" "PAYPAL" "STRIPE". The product's payment methods in array format.                        |
|   `additional_information`  |      array      |     ❌    |                                Additional info that can be requested from the customer during the checkout process.                               |
|       `bulk_discount`       |      array      |     ❌    |                                  An array of discounts when a customer purchases more than a specified quantity.                                  |
| `minimum_purchase_quantity` |       int       |    ✔️    |                                                 The minimum amount a customer is able to purchase.                                                |
| `maximum_purchase_quantity` |     int/null    |     ❌    |                                                 The maximum amount a customer is able to purchase.                                                |
|          `webhook`          |   string/null   |     ❌    |                                          A webhook URL that will receive updates when orders are placed.                                          |
|          `warranty`         |   object/null   |     ❌    |                                         The warranty time in which a customer is able to request a refund.                                        |
|           `locked`          |     boolean     |     ❌    |                                            Whether this product is locked by the admins or moderators.                                            |
|          `section`          |     int/null    |     ❌    |                              The ID of a section to associate with this product. Use null to disassociate a section.                              |
|         {% endtab %}        |                 |          |                                                                                                                                                   |
|        {% endtabs %}        |                 |          |                                                                                                                                                   |

<details>

<summary>Usage</summary>

```javascript
const Sellapp = require("sellapp-node");
const API = new Sellapp.API("YOUR_API_KEY");

API.variants.updateProductVariant("6666, {
	"title": "Millions of gold pieces EXTRA",
	"slug": "millions-of-gold-pieces",
	"description": "Get rich, buy this.",
	"visibility": "PUBLIC",
	"deliverable": {
		"delivery_text": "Meet me in world 1000!!",
		"type": "MANUAL",
		"data": {
			"stock": 666,
			"comment": "Thanks broski (scammed, real)"
		}
	},
	"price": {
		"price": 1000, // ( ͡° ͜ʖ ͡°)
		"currency": "USD"
	},
	"humble": true,
	"payment_methods": ["PAYPAL"],
	"minimum_purchase_quantity": 1,
	"maximum_purchase_quantity": 20
}).then((res) => {
    console.log(res); 
}).catch((err) => {
    console.log(err);
});
```

</details>

***

### `deleteProductVariant()`

| Parameters |  Type  | Required |   Description   |
| :--------: | :----: | :------: | :-------------: |
|    `vid`   | string |    ✔️    | ID of a Variant |

<details>

<summary>Usage</summary>

```javascript
const Sellapp = require("sellapp-node");
const API = new Sellapp.API("YOUR_API_KEY");

API.variants.deleteProductVariant("6666").then((res) => {
    console.log(res)
})
```

</details>
