# Stock y Precios

## Update Stock

<mark style="color:green;">`POST`</mark> `https://ventiapi.azurewebsites.net/api/stock/updatestock`

Se deberá hacer post con un arreglo de datos que contengan el SKU y el Stock asociado. Esta función subirá los datos a Ventiapp y la plataforma se encargará de actualizar a todos los canales donde estén activas sus publicaciones. Se soporta hasta 50 SKU's por llamada.<br>

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

{% tabs %}
{% tab title="200 Stock actualizado correctamente" %}

```javascript
[{
     "sites": "mercadoshops: OK, mercadolibre: OK",
     "status": "success",
     "msg": "Stock update requested"
     "sku": "33QH-QQ1",
     "quantity":50,
     "jobId":12345
 },{
     "sites": "mercadoshops: OK, mercadolibre: OK",
     "status": "success",
     "msg": "Stock update requested",
     "sku": "33QH-QQ2",
     "quantity":55,
     "jobId":12345
 }]
```

{% endtab %}
{% endtabs %}

Body parameters

```javascript
[
  {
    "sku": "34HHB-QQ1",
    "quantity": 50
  },
  {
    "sku": "34HHB-QQ2",
    "quantity": 55
  }
]
```

{% hint style="warning" %}
Los valores de cantidades menores 0 serán traducidos como un 0 ya que los canales no soportan números negativos
{% endhint %}

## Update Price

<mark style="color:green;">`POST`</mark> `https://ventiapi.azurewebsites.net/api/stock/updatepriceV2`

Se deberá hacer post con un arreglo de datos que contengan el SKU y el Precio asociado. Esta función subirá los datos a VentiApp y la plataforma se encargará de actualizar a todos los canales donde estén activas sus publicaciones. Se soporta hasta 50 SKU's por llamada.

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

{% tabs %}
{% tab title="200 Precio actualizado correctamente" %}

```javascript
[{
     "sites": "mercadolibre: OK",
     "status": "success",
     "msg": "Price update requested"
     "sku": "33QH-QQ1",
     "price":199.99,
     "jobId":12345
 },{
     "sites": "mercadoshops: OK",
     "status": "success",
     "msg": "Price update requested",
     "sku": "33QH-QQ2",
     "price":299.99,
     "jobId":12345
 }]
```

{% endtab %}
{% endtabs %}

Body parameters

```javascript
[
  {
    "sku": "34HHB-QQ1",
    "price":199.99,
    "channel": "mercadolibre"
  },
  {
    "sku": "34HHB-QQ2",
    "price": 299.99,
    "channel": "mercadoshops"
  }
]
```

## Update Price Stock By Channel

<mark style="color:green;">`POST`</mark> `https://ventiapi.azurewebsites.net/api/stock/updatepricestockbychannel`

Esta función se puede utilizar para actualizar stock y precio diferenciado por canal, estos campos pueden ser opcionales, no es obligatorio enviar ambos. El campo que es obligatorio es el del canal. Esta llamada tiene como límite un SKU's en simultáneo.

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

{% tabs %}
{% tab title="200
El campo sites indica si hubo alguna falla en ese canal en particular" %}

```javascript
{
    "sites": "",
    "result": "success",
    "msg": "Update requested"
}
```

{% endtab %}
{% endtabs %}

Body parameters

```javascript
{
        "sku": "34HHB-QQ1",
        "channelData": [{
                "channel": "mercadolibre",
                "quantity": 40,
                "price": 155.40,
                "availableDays":2,
                "listing_type" : "clasica" //OPTIONAL. values=> premium o clasica
            },
            {
                "channel": "linio",
                "quantity":20,
            },{
                "channel": "prestashop",
                "quantity": 40,
                "price": 140.40,
                "salePrice": 100.50 //ESTE PARÁMETRO ES OPCIONAL
            }
        ]
}
```

#### Actualización 1.0.7

Se agrega campo **availableDays** para indicar la disponibilidad en días del producto (Esto solamente aplica para Mercado Libre en cuanto liberen su API)

## Get Price Stock By Channel

<mark style="color:blue;">`GET`</mark> `https://ventiapi.azurewebsites.net/api/stock/getpricestockbychannel/{sku}/`

Esta función se puede utilizar para obtener el stock y precio diferenciado por canal. Simplemente hay que remplazar el SKU de la url por el deseado.\
Si el SKU utiliza caracteres como puntos o comas, es recomendado poner la barra al final del query string

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

{% tabs %}
{% tab title="200 Respuesta de ejemplo" %}

```javascript
{
    "sku": "ElektraSku1-1",
    "channelData": [
        {
            "channel": "meli",
            "quantity": 94,
            "price": 234.00,
            "salePrice": null,
            "externalId": "MLM760079428",
            "permalink": "http://articulo.mercadolibre.com.mx/MLM-760079428-elektra1-_JM",
            "status": "under_review"
        },
        {
            "channel": "wish",
            "quantity": 0,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "claroshop",
            "quantity": 0,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "vtex",
            "quantity": 0,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "liverpool",
            "quantity": 2,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "walmartedi",
            "quantity": 2,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "elektra",
            "quantity": 94,
            "price": 234.00,
            "salePrice": null,
            "externalId": "1624988838125",
            "permalink": null,
            "status": "PENDING_APPROVAL"
        },
        {
            "channel": "woocommerce",
            "quantity": 94,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": "",
            "status": "unpublished"
        },
        {
            "channel": "amazonus",
            "quantity": 2,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        },
        {
            "channel": "walmartus",
            "quantity": 2,
            "price": 234.00,
            "salePrice": null,
            "externalId": "",
            "permalink": null,
            "status": "unpublished"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Update Price By ErpId

<mark style="color:green;">`POST`</mark> `https://ventiapi.azurewebsites.net/api/stock/updatepricebyerpid`

&#x20;Esta función funciona de manera similar a **Update Price** pero requiere el ID del ERP. Esta función solamente se debería de invocar en caso de tener una integración custom de Ventiapp con su ERP.

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

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

```javascript
[{
   "33QH-QQ1": {
     "sites": "mercadoshops: OK, mercadolibre: OK",
     "status": "success",
     "msg": "Price updated successfully"
   }
 }, {
   "33QH-QQ2": {
     "sites": "mercadoshops: OK, mercadolibre: OK",
     "status": "success",
     "msg": "Price updated successfully"
   }
 }]
```

{% endtab %}
{% endtabs %}

Body parameters

```javascript
[
  {
    "internalId": "34HHB-QQ1",
    "price":199.99
  },
  {
    "internalId": "34HHB-QQ2",
    "price": 299.99
  }
]
```

## Update Price And Stock Async

<mark style="color:green;">`POST`</mark> `https://ventiapi.azurewebsites.net/api/stock/UpdatePriceAndStockAsync`

Se deberá utilizar esta opción cuando se desee procesar largas cantidades de SKU's. Recomendado correr en horarios nocturnos por el tiempo que puede demorar el procesamiento de los datos.\
\
Se deberá utilizar esta opción cuando se desee procesar largas cantidades de SKU's ó el canal deseado esté demorando mucho en responder con algún endpoint anterior.\
\
Este proceso genera una tarea dentro de Ventiapp. El resultado de esta misma se puede consultar desde el frontend, ó desde el endpoint GetStatusRequest

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer +token    |
| Content-Type  | string | application/json |

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

```javascript
{
    "status": "sent",
    "msg": "request sent",
    "jobId": "9999"
}
```

{% endtab %}
{% endtabs %}

Body Parameters

```javascript
[
  {
    "sku": "34HHB-QQ1",
    "quantity": "10"
  },
{
    "sku": "34HHB-QQ2",
    "quantity": "15",
    "price": "99.99",
    "publishingPrice": "99.99"
  }
]
```

## Get Products Stock Price

<mark style="color:blue;">`GET`</mark> `https://ventiapi.azurewebsites.net/api/stock/GetProductsStockPrice?offset=0&paging=50`

Este método devuelve los productos con Stock y Precio de manera general

Canales permitidos

MercadoLibre (meli)

Linio (linio)

Shopify (shopify)

Claroshop (claroshop)

Amazon (amazon)

Mercadoshops (mshops)

WooCommerce (woocommerce)

Magento (magento)

Walmart (walmartedi)

Wish (wish)

Elektra (elektra)

Liverpool (liverpool)

VentiCommerce (venticommerce)

Amazon US (amazonus)

Walmart US (walmartus)

Tienda Nube (tiendanube)

#### Path Parameters

| Name    | Type   | Description                                               |
| ------- | ------ | --------------------------------------------------------- |
| offset  | int    | Offset para paginación                                    |
| paging  | int    | Tamaño de página, máximo 50                               |
| channel | string | Canal específico                                          |
| sort    | string | Ordenación de resultados, posibles: alph\_asc, alph\_desc |

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

```json
{
    "offset": 0,
    "paging": 50,
    "total": 2,
    "results": [
        {
            "sku": "0GY",
            "channelData": [
                {
                    "channel": "elektra",
                    "quantity": 1,
                    "price": 2760.00,
                    "salePrice": null,
                    "externalId": "",
                    "permalink": null,
                    "status": "unpublished"
                },
                {
                    "channel": "shopify",
                    "quantity": 2,
                    "price": 2699.00,
                    "salePrice": null,
                    "externalId": "6608400187523",
                    "permalink": "https://kubostore3.myshopify.com/products/mochila-tommy",
                    "status": "active"
                },
                {
                    "channel": "mshops",
                    "quantity": 0,
                    "price": 2760.00,
                    "salePrice": null,
                    "externalId": "MLM1630893194",
                    "permalink": "http://articulo.mercadolibre.com.mx/MLM-1630893194-mochila-tommy-_JM",
                    "status": "paused"
                }
                {
                    "channel": "claroshop",
                    "quantity": 1,
                    "price": 2760.00,
                    "salePrice": null,
                    "externalId": "",
                    "permalink": null,
                    "status": "unpublished"
                },
                {
                    "channel": "tiendanube",
                    "quantity": 1,
                    "price": 2760.00,
                    "salePrice": null,
                    "externalId": "",
                    "permalink": null,
                    "status": "unpublished"
                }
            ]
        },
        {
            "sku": "120-3",
            "channelData": [
                {
                    "channel": "elektra",
                    "quantity": 10,
                    "price": 100.00,
                    "salePrice": null,
                    "externalId": "",
                    "permalink": null,
                    "status": "unpublished"
                },
                {
                    "channel": "shopify",
                    "quantity": 146,
                    "price": 100.00,
                    "salePrice": null,
                    "externalId": "7725102137475",
                    "permalink": "https://kubostore3.myshopify.com/products/producto-2",
                    "status": "active"
                }
            ]
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Get Status Request (deprecado en Enero 2020)

<mark style="color:blue;">`GET`</mark> `https://ventiapi.azurewebsites.net/api/stock/GetStatusRequest`

Este método retorna el estado de la tarea asyncrónica generada previamente

#### Path Parameters

| Name  | Type   | Description             |
| ----- | ------ | ----------------------- |
| jobId | number | Id de la tarea generada |

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer + token   |
| Content-Type  | string | application/json |

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

```
```

{% endtab %}
{% endtabs %}

## Get Job Status

<mark style="color:blue;">`GET`</mark> `https://ventiapi.azurewebsites.net/api/stock/GetStockPriceJob`

Este método retorna el estado de los cambios encolados por Update Stock o Update Price

#### Path Parameters

| Name   | Type   | Description             |
| ------ | ------ | ----------------------- |
| offset | number | Posición de la página   |
| size   | number | Tamaño de la pagina     |
| jobId  | number | Id de la tarea generada |

#### Headers

| Name          | Type   | Description      |
| ------------- | ------ | ---------------- |
| Authorization | string | Bearer + token   |
| Content-Type  | string | application/json |

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

```javascript
[
    {
        "sku": "AW0AW08459-RBL",
        "stock": 2,
        "price": null,
        "priceOffer": null,
        "status": "Finalizado",
        "integration": "Mercado Libre"
    },
    {
        "sku": "AW0AW08479-R8L",
        "stock": 2,
        "price": null,
        "priceOffer": null,
        "status": "Finalizado",
        "integration": "Mercado Libre"
    }
]
```

{% endtab %}
{% endtabs %}
