# Purchases

### POST /purchases

Create a new purchase. This endpoint is ***near real time***, the purchase will be enqueued to be processed.

**Important: only one of the customers identifier** (email, document, service\_uid) **is required** so the API can relate the purchase to an use&#x72;**. Using hard identifiers is highly recommended.**

{% hint style="danger" %}
Maximum size of data sent is **256KB**
{% endhint %}

The json with the purchase 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 representation of a purchase",
    "type": "object",
    "anyOf": [
        {"required": ["service_uid", "invoice_number", "purchase_detail", "prices"]},
        {"required": ["email", "invoice_number", "purchase_detail", "prices"]},
        {"required": ["document", "invoice_number", "purchase_detail", "prices"]},
        {"required": ["telephone", "invoice_number", "purchase_detail", "prices"]}
    ],
    "properties": {
        "service_uid": { "type": "string" },
        "email": { "type": "string" },
        "document": { "type": "string" },
        "telephone": { "type": "string" },
        "points": { "type": "number", "multipleOf": 1 },
        "invoice_number": { "type": ["string", "integer"] },
        "channel":{"type": "string",
                    "enum": ["web","telephone", "in-store", "corporate", "direct", "other"]
                },
        "purchase_detail": {
            "type": "array",
            "items": {
                "type": "object",
                "required": ["sku", "quantity", "unit_price"],
                "properties": {
                    "sku": {
                        "type": "string",
                        "minLength": 1,
                        "pattern": "^[^-][a-zA-Z0-9_%-]+$"
                    },
                    "base_name": {"type": "string"},
                    "product_name": {"type": "string"},
                    "category": {
                        "type": "array",
                        "items": {
                            "oneOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "object",
                                    "required": ["id", "name" ],
                                    "properties": {
                                        "id": { "type": "string" },
                                        "name": { "type": "string" },
                                        "url": { "type": "string" },
                                        "image_url": { "type": "string" }
                                    }
                                }
                            ]
                        }
                    },
                    "quantity": { "type": "integer" },
                    "unit_price": { "type": "number" },
                    "variations": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "required": ["name", "value"],
                            "properties": {
                                "name": {"type": "string"},
                                "value": {"type": "string"}
                            }
                        }
                    },
                    "specifications": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "required": ["name", "value"],
                            "properties": {
                                "name": { "type": "string" },
                                "value": { "type": "string" }
                            }
                        }
                    },
                    "brand": {"type": "string"},
                    "description": {"type": "string"},
                    "url": {"type": "string"},
                    "image_url": {"type": "string"},
                    "thumbnail_url": {"type": "string"},
                    "stock": {"type": "number"},
                    "available": {"type": "boolean"},
                    "manufacturer_warranty_date": {"type": "date"},
                    "extension_warranty_date": {"type": "date"},
                    "with_extension_warranty": {"type": "boolean"},
                    "custom_attributes": { "type": "object" }
                }
            }
        },
        "prices": {
            "type": "object",
            "required": ["total"],
            "properties": {
                "cost": { "type": "number" },
                "shipping": { "type": "number" },
                "gross": { "type": "number" },
                "tax": { "type": "number" },
                "discount": { "type": "number" },
                "total": { "type": "number" }
            }
        },
        "payment": {
            "oneOf": [
                {
                    "type": "object",
                    "required": ["type"],
                    "properties": {
                        "type":  { "type": "string",
                        "enum": ['credit', 'debit', 'cash', 'mercadopago', 'other']
                        },
                        "brand": { "type": "string" },
                        "bank":  { "type": "string" },
                        "total":  { "type": "float" },
                        "installments":  { "type": "integer" },
                        "card_first_digits":  { "type": "string", "pattern": "^[0-9]{6}$" }
                    }
                },
                {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["type","total"],
                        "properties": {
                            "type":  { "type": "string",
                            "enum": ['credit', 'debit', 'cash', 'mercadopago', 'other']
                            },
                            "brand": { "type": "string" },
                            "bank":  { "type": "string" },
                            "total":  { "type": "float" },
                            "installments":  { "type": "integer" },
                            "card_first_digits":  { "type": "string", "pattern": "^[0-9]{6}$" }
                        }
                    }
                }
            ]
        },
        "branch_name": { "type": "string" },
        "seller": {
            "type": "object",
            "required": ["name", "email"],
            "properties": {
                "name": { "type": "string"},
                "email": { "type": "string", "format": "email" },
                "external_id": { "type": "string" }
            }
        },
        "createtime": { "type": "string" },
        "approvedtime": { "type": "string" },
        "metadata": { "type": "object" },
        "custom_attributes": { "type": "object" }
    }
}
```

**Example**

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

```
{
  "document": "123456789",
  "points": 24,
  "invoice_number": "FAC-000085643",
  "channel": "web",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "Heladera Patrick",
      "base_name": "Heladera Patrick",
      "category": [
        { "id": "a", "name": "Electrodomésticos"},
        { "id": "a-b", "name": "Linea blanca"},
        { "id": "a-b-c", "name": "Heladeras"}
      ],
      "quantity": 1,
      "unit_price": 1999.00,
      "variations": [
        {
          "name": "Volumen",
          "value": "100 lts"
        }
      ],
      "brand": "Patrick",
      "description": "Su capacidad total de almacenamiento es de 280 litros. El espacio para refrigerador cuenta con 204 litros para ordenar alimentos y bebidas y el freezer tiene un total de 76 litros para congelados.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 10,
      "available": true,
      "specifications": [
        {"name": "Garantia del Fabricante", "value": "12 meses"},
        {"name": "Alto", "value": "143.3 cm"},
        {"name": "Ancho", "value": "60.9 cm"}
      ],
      "manufacturer_warranty_date": "2018-12-31 23:59:59",
      "extension_warranty_date": "2020-12-31 23:59:59",
      "with_extension_warranty": true,
      "custom_attributes": { 
        "millas_aerolineas_plus": 300,
        "codigo_dto": "2354XFD45" 
      }
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 1800.00,
    "tax": 199.00,
    "discount": 100.00,
    "total": 1899.00
  },
  "payment":{
    "type":"credit",
    "brand":"Visa",
    "bank": "Example Bank",
    "total": 1899.00,
    "installments": 12,
    "card_first_digits": "123456"
  },
  "branch_name": "Palermo I",
  "seller":{
    "name": "Seller Relles",
    "email": "seller@email.com",
    "external_id": "0001"
  },
  "createtime": "2017-03-23 14:35:22",
  "approvedtime": "2017-03-23 14:35:22",
  "custom_attributes": { 
    "fecha_max_cambio": "2017-03-26"
  }
}
```

This is an example:

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

```bash
curl -X POST \
  https://api.woowup.com/apiv3/purchases \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d '{
  "document": "123456789",
  "points": 24,
  "invoice_number": "FAC-000085643",
  "channel": "web",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "Heladera Patrick",
      "base_name": "Heladera Patrick",
      "category": [
        { "id": "a", "name": "Electrodomésticos"},
        { "id": "a-b", "name": "Linea blanca"},
        { "id": "a-b-c", "name": "Heladeras"}
      ],
      "quantity": 1,
      "unit_price": 1999.00,
      "variations": [
        {
          "name": "Volumen",
          "value": "100 lts"
        }
      ],
      "brand": "Patrick",
      "description": "Su capacidad total de almacenamiento es de 280 litros. El espacio para refrigerador cuenta con 204 litros para ordenar alimentos y bebidas y el freezer tiene un total de 76 litros para congelados.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 10,
      "available": true,
      "specifications": [
        {"name": "Garantia del Fabricante", "value": "12 meses"},
        {"name": "Alto", "value": "143.3 cm"},
        {"name": "Ancho", "value": "60.9 cm"}
      ],
      "manufacturer_warranty_date": "2018-12-31 23:59:59",
      "extension_warranty_date": "2020-12-31 23:59:59",
      "with_extension_warranty": true,
      "custom_attributes": { 
        "millas_aerolineas_plus": 300,
        "codigo_dto": "2354XFD45" 
      }
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 1800.00,
    "tax": 199.00,
    "discount": 100.00,
    "total": 1899.00
  },
  "payment":{
    "type":"credit",
    "brand":"Visa",
    "bank": "Example Bank",
    "total": 1899.00,
    "installments": 12,
    "card_first_digits": "123456"
  },
  "branch_name": "Palermo I",
  "seller":{
    "name": "Seller Relles",
    "email": "seller@email.com",
    "external_id": "0001"
  },
  "createtime": "2017-03-23 14:35:22",
  "approvedtime": "2017-03-23 14:35:22",
  "custom_attributes": { 
    "fecha_max_cambio": "2017-03-26"
  }
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$purchase = {{purchase}};

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.woowup.com/apiv3/purchases",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $purchase,
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "cache-control: no-cache,no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases"

payload = {{purchase}}
headers = {
    'accept': "application/json",
    'authorization': "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    'cache-control': "no-cache,no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Errors**

| HttpCode | HttpCode Name     | Code                         | Description                                       |
| -------- | ----------------- | ---------------------------- | ------------------------------------------------- |
| 200      | ok                | ok                           | Purchase successfully saved                       |
| 400      | bad request       | bad\_request                 | Invalid parameters, view message for more details |
| 429      | too many requests | too\_many\_requests          | API's requests-per-second limit exceeded          |
| 500      | internal error    | user\_not\_found             | User not found                                    |
| 500      | internal error    | duplicated\_purchase\_number | Duplicated purchase number                        |
| 500      | internal error    | internal\_error              | Unexpected error                                  |

### POST /purchases/bulk

Create multiple purchases in one request. This endpoint is equal to `/purchases` but accept an array of purchases. This is an example with 2 purchases in one request:

{% hint style="danger" %}
Maximum size per purchase sent is **256KB**
{% endhint %}

```bash
curl -X POST \
  https://api.woowup.com/apiv3/purchases \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d '[{
  "document": "123456789",
  "points": 24,
  "invoice_number": "FAC-000085643",
  "channel": "web",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "Heladera Patrick",
      "base_name": "Heladera Patrick",
      "category": [
        { "id": "a", "name": "Electrodomésticos"},
        { "id": "a-b", "name": "Linea blanca"},
        { "id": "a-b-c", "name": "Heladeras"}
      ],
      "quantity": 1,
      "unit_price": 1999.00,
      "variations": [
        {
          "name": "Volumen",
          "value": "100 lts"
        }
      ],
      "brand": "Patrick",
      "description": "Su capacidad total de almacenamiento es de 280 litros. El espacio para refrigerador cuenta con 204 litros para ordenar alimentos y bebidas y el freezer tiene un total de 76 litros para congelados.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 10,
      "available": true,
      "specifications": [
        {"name": "Garantia del Fabricante", "value": "12 meses"},
        {"name": "Alto", "value": "143.3 cm"},
        {"name": "Ancho", "value": "60.9 cm"}
      ],
      "custom_attributes": { 
      	"millas_aerolineas_plus": 300,
      	"codigo_dto": "2354XFD45" 
      }
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 1800.00,
    "tax": 199.00,
    "discount": 100.00,
    "total": 1899.00
  },
  "payment":{
    "type":"debit",
    "brand":"Amex",
    "bank": "Example Bank"
  },
  "branch_name": "Palermo I",
  "createtime": "2017-03-23 14:35:22",
  "custom_attributes": { 
  	"fecha_max_cambio": "2017-03-26"
  }
},
{
  "document": "987654321",
  "points": 24,
  "invoice_number": "FAC-000085644",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "TV Samsung",
      "base_name": "TV Samsung",
      "category": [
        { "id": "x", "name": "Electrodomésticos"},
        { "id": "x-y", "name": "Hogar"},
        { "id": "x-y-z", "name": "TV"}
      ],
      "quantity": 1,
      "unit_price": 3500.00,
      "variations": [
        {
          "name": "Tamaño",
          "value": "42 pulgadas"
        }
      ],
      "brand": "Samsung",
      "description": "Pasá videos, música y fotos desde tu móvil o PC a tu TV mediante una conexión sencilla gracias a la aplicación Samsung View.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 20,
      "available": true,
      "specifications": [
        {"name": "Profundidad (con base)", "value": "29.4 cm"},
        {"name": "Alto", "value": "71 cm"},
        {"name": "Ancho", "value": "110 cm"}
      ]
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 3300.00,
    "tax": 200.00,
    "discount": 100.00,
    "total": 3400.00
  },
  "payment":{
    "type":"credit",
    "brand":"Visa",
    "bank": "Another Bank"
  },
  "branch_name": "Palermo I",
  "seller":{
    "name": "Seller Relles",
    "email": "seller@email.com",
    "external_id": "0001"
  },
  "createtime": "2017-03-23 14:35:22"
}]'
```

**Errors**

| HttpCode | HttpCode Name     | Code                         | Description                                       |
| -------- | ----------------- | ---------------------------- | ------------------------------------------------- |
| 200      | ok                | ok                           | Purchases successfully saved                      |
| 400      | bad request       | bad\_request                 | Invalid parameters, view message for more details |
| 429      | too many requests | too\_many\_requests          | API's requests-per-second limit exceeded          |
| 500      | internal error    | user\_not\_found             | User not found                                    |
| 500      | internal error    | duplicated\_purchase\_number | Duplicated purchase number                        |
| 500      | internal error    | internal\_error              | Unexpected error                                  |

### PUT /purchases

Update a purchase. This endpoint is ***near real time***, the purchase will be enqueued to be processed.

{% hint style="danger" %}
Maximum size of data sent is **256KB**
{% endhint %}

**Example**

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

```
{
  "document": "1234567890",
  "points": 24,
  "invoice_number": "FAC-000085643",
  "channel": "web",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "Heladera Patrick",
      "base_name": "Heladera Patrick",
      "category": [
        { "id": "a", "name": "Electrodomésticos"},
        { "id": "a-b", "name": "Linea blanca"},
        { "id": "a-b-c", "name": "Heladeras"}
      ],
      "quantity": 1,
      "unit_price": 1999.00,
      "variations": [
        {
          "name": "Volumen",
          "value": "100 lts"
        }
      ],
      "brand": "Patrick",
      "description": "Su capacidad total de almacenamiento es de 280 litros. El espacio para refrigerador cuenta con 204 litros para ordenar alimentos y bebidas y el freezer tiene un total de 76 litros para congelados.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 10,
      "available": true,
      "specifications": [
        {"name": "Garantia del Fabricante", "value": "12 meses"},
        {"name": "Alto", "value": "143.3 cm"},
        {"name": "Ancho", "value": "60.9 cm"}
      ],
      "custom_attributes": { 
      	"millas_aerolineas_plus": 500,
      	"codigo_dto": "20054XFD46" 
      }
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 1800.00,
    "tax": 199.00,
    "discount": 100.00,
    "total": 1899.00
  },
  "payment":{
    "type":"credit",
    "brand":"Visa",
    "bank": "Example Bank"
  },
  "branch_name": "Palermo I",
  "seller":{
    "name": "Seller Relles",
    "email": "seller@email.com",
    "external_id": "0001"
  },
  "createtime": "2017-03-23 14:35:22",
  "approvedtime": "2017-03-23 14:35:22",
  "custom_attributes": { 
	"fecha_max_cambio": "2017-03-30"
  }
}
```

This is an example:

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

```bash
curl -X PUT \
  https://api.woowup.com/apiv3/purchases \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d '{
  "document": "1234567890",
  "points": 24,
  "invoice_number": "FAC-000085643",
  "channel": "web",
  "purchase_detail": [
    {
      "sku": "2907362",
      "product_name": "Heladera Patrick",
      "base_name": "Heladera Patrick",
      "category": [
        { "id": "a", "name": "Electrodomésticos"},
        { "id": "a-b", "name": "Linea blanca"},
        { "id": "a-b-c", "name": "Heladeras"}
      ],
      "quantity": 1,
      "unit_price": 1999.00,
      "variations": [
        {
          "name": "Volumen",
          "value": "100 lts"
        }
      ],
      "brand": "Patrick",
      "description": "Su capacidad total de almacenamiento es de 280 litros. El espacio para refrigerador cuenta con 204 litros para ordenar alimentos y bebidas y el freezer tiene un total de 76 litros para congelados.",
      "url": "http://www.example.com/example",
      "image_url": "http://www.example.com/example",
      "thumbnail_url": "http://www.example.com/example",
      "stock": 10,
      "available": true,
      "specifications": [
        {"name": "Garantia del Fabricante", "value": "12 meses"},
        {"name": "Alto", "value": "143.3 cm"},
        {"name": "Ancho", "value": "60.9 cm"}
      ],
      "custom_attributes": { 
      	"millas_aerolineas_plus": 500,
      	"codigo_dto": "20054XFD46" 
      }
    }
  ],
  "prices": {
    "cost": 800.00,
    "shipping": 120.00,
    "gross": 1800.00,
    "tax": 199.00,
    "discount": 100.00,
    "total": 1899.00
  },
  "payment":{
    "type":"credit",
    "brand":"Visa",
    "bank": "Example Bank"
  },
  "branch_name": "Palermo I",
  "seller":{
    "name": "Seller Relles",
    "email": "seller@email.com",
    "external_id": "0001"
  },
  "createtime": "2017-03-23 14:35:22",
  "approvedtime": "2017-03-23 14:35:22",
  "custom_attributes": { 
	"fecha_max_cambio": "2017-03-30"
  }
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$purchase = {{purchase}};

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.woowup.com/apiv3/purchases",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => $purchase,
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "cache-control: no-cache,no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases"

payload = {{purchase}}
headers = {
    'accept': "application/json",
    'authorization': "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    'cache-control': "no-cache,no-cache"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Errors**

| HttpCode | HttpCode Name     | Code                         | Description                                       |
| -------- | ----------------- | ---------------------------- | ------------------------------------------------- |
| 200      | ok                | ok                           | Purchase successfully updated                     |
| 400      | bad request       | bad\_request                 | Invalid parameters, view message for more details |
| 429      | too many requests | too\_many\_request           | API's requests-per-second limit exceeded          |
| 500      | internal error    | user\_not\_found             | User not found                                    |
| 500      | internal error    | inexistent\_purchase\_number | Purchase number inexistent                        |
| 500      | internal error    | internal\_error              | Unexpected error                                  |

### GET /purchases

Search a purchase.

| Parameter       | Type  | Required | Description                           |
| --------------- | ----- | -------- | ------------------------------------- |
| invoice\_number | query | No       |                                       |
| service\_uid    | query | No       |                                       |
| branch\_name    | query | No       |                                       |
| branch\_id      | query | No       | Is only used together invoice\_number |

{% hint style="info" %}

```
Query by invoice_number returns only the first purchase created.
```

{% endhint %}

**Example**

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

```bash
curl -X GET \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  "https://api.woowup.com/apiv3/purchases?service_uid=12345"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.woowup.com/apiv3/purchases?service_uid=12345",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "cache-control: no-cache,no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases"

querystring = {"service_uid":"12345"}

headers = {
    'accept': "application/json",
    'authorization': "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    'cache-control': "no-cache,no-cache",
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

```
{
    "payload": [
        {
            "service_uid": "12345",
            "document": "23456789",
            "email" "email@example.com",
            "invoice_number": "00001",
            "channel": null,
            "purchase_detail": {
                "items": [
                    {
                        "product_id": "543V",
                        "product_name": "Manta Panal",
                        "quantity": 1,
                        "price": 1999,
                        "custom_attributes": {
                            "codigo_dto": "2354XFD45",
                            "millas_aerolineas_plus": 300
                        }
                    }
                ]
            },
            "prices": {
                "total": 1999,
                "gross": 1999,
                "discount": 0,
                "shipping": 0,
                "tax": 0,
                "cost": 0
            },
            "points": 0,
            "downloadtime": "2018-05-10 23:30:49",
            "createtime": "2018-05-10 23:30:49",
            "custom_attributes": {
                "fecha_max_cambio": "2017-03-26 00:00:00"
            },
            "cancel_transaction_id": null,
            "branch": null,
            "payment": {
                "type": "other",
                "brand": null,
                "name": null
            },
            "purchase_operator": null,
            "pickup_store": "SHOPPING LOCAL 1",
            "promotions": null
        },
        {
            "service_uid": "12345",
            "document": "23456789",
            "email" "email@example.com",
            "invoice_number": "00002",
            "channel": null,
            "purchase_detail": {
                "items": [
                    {
                        "product_id": "123V",
                        "product_name": "Botas Color Rosa",
                        "quantity": 1,
                        "price": 1999
                    }
                ]
            },
            "prices": {
                "total": 1999,
                "gross": 1999,
                "discount": 0,
                "shipping": 0,
                "tax": 0,
                "cost": 0
            },
            "points": 0,
            "downloadtime": "2018-05-10 23:30:49",
            "createtime": "2018-05-10 23:30:49",
            "cancel_transaction_id": null,
            "branch": null,
            "payment": {
                "type": "other",
                "brand": null,
                "name": null
            },
            "purchase_operator": null,
            "pickup_store": "SHOPPING LOCAL 1",
            "promotions": null
        }
    ],
    "message": "ok",
    "code": "ok",
    "time": "62ms"
}
```

**Errors**

| HttpCode | HttpCode Name     | Code                | Description                                       |
| -------- | ----------------- | ------------------- | ------------------------------------------------- |
| 200      | ok                | ok                  | Request successful                                |
| 400      | bad request       | bad\_request        | Invalid parameters, view message for more details |
| 404      | not found         | not\_found          | Purchase not found                                |
| 429      | too many requests | too\_many\_requests | API's requests-per-second limit exceeded          |
| 500      | internal error    | internal\_error     | Unexpected error                                  |

### GET /purchases/iin/{firstSixDigits}

Retrieve information about bank by first six digits of credit/debit card

| Parameter      | Type | Required | Description                          |
| -------------- | ---- | -------- | ------------------------------------ |
| firstSixDigits | url  | Yes      | First six digit of credit/debit card |

#### Example

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

```bash
curl -X GET \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  "https://api.woowup.com/apiv3/purchases/iin/123456"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.woowup.com/apiv3/purchases/iin/123456",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "cache-control: no-cache,no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases/iin/123456"

headers = {
    'accept': "application/json",
    'authorization': "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    'cache-control': "no-cache,no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}

#### Response

```javascript
{
    "payload": {
        "scheme": "visa",
        "brand": "Visa/Dankort",
        "type": "debit",
        "prepaid": "",
        "country": "DK",
        "bank": {
            "name": "Spar Nord",
            "logo": "",
            "url": "www.sparnord.dk",
            "phone": "",
            "city": ""
        }
    },
    "message": "ok",
    "code": "ok",
    "time": "109ms"
}
```

#### Errors

| HTTP Code | HTTP Code Name    | Decription        |
| --------- | ----------------- | ----------------- |
| 200       | Ok                | Succesful request |
| 404       | Not Found         | IIN not found     |
| 429       | Too Many Requests | Too Many Requests |
| 500       | Internal Error    | Unexpected error  |

## Delete purchase

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

Delete a purchase

#### Request Body

| Name            | Type   | Description |
| --------------- | ------ | ----------- |
| invoice\_number | string |             |
| branch\_name    | string |             |

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

```javascript
{
    "payload": [],
    "message": "ok",
    "code": "ok",
    "time": "98ms"
}
```

{% endtab %}

{% tab title="400 " %}

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

{% endtab %}

{% tab title="403 " %}

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

{% endtab %}

{% tab title="404 " %}

```javascript
//purchase
{
    "payload": {
        "errors": [
            "purchase not found"
        ]
    },
    "message": "purchase not found",
    "code": "not_found",
    "time": "77ms"
}

//branch
{
    "payload": {
        "errors": [
            "branch not found"
        ]
    },
    "message": "branch not found",
    "code": "not_found",
    "time": "70ms"
}
```

{% endtab %}

{% tab title="500 " %}

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

{% endtab %}
{% endtabs %}

**Example**

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

```bash
curl -X DELETE \
  https://api.woowup.com/apiv3/purchases \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic XXXXXXXXXXXXXXXXXXXX' \
  -H 'Content-Type: application/json' \
  -d '{
	"invoice_number": "987654321"
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases"

payload = "{\"invoice_number\": \"987654321\"}"
headers = {
    'Accept': "application/json",
    'Authorization': "Basic XXXXXXXXXXXXXXXXXXXX",
    'Content-Type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("DELETE", url, data=payload, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

```javascript
{
    "payload": [],
    "message": "ok",
    "code": "ok",
    "time": "98ms"
}
```

## Delete purchases (bulk)

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

#### Request Body

| Name         | Type   | Description                                   |
| ------------ | ------ | --------------------------------------------- |
| branch\_name | string |                                               |
| from         | string | date format YYYY-MM-DD hh:mm:ss (in UTC time) |
| to           | string | date format YYYY-MM-DD hh:mm:ss (in UTC-time) |
| notify\_to   | string | email to receive the confirmation             |

{% tabs %}
{% tab title="200 will be receive an email when the deletion process is finished" %}

```javascript
{
    "payload": {
        "request_id": "XXX"
    },
    "message": "ok",
    "code": "ok",
    "time": "111ms"
}
```

{% endtab %}

{% tab title="400 " %}

```javascript
//bad_request
{
    "payload": {
        "errors": [
            "Failed matching any of the provided schemas."
        ]
    },
    "message": "bad request",
    "code": "bad_request",
    "time": "38ms"
}

//invalid_email
{
    "payload": [],
    "message": "Invalid email to notify",
    "code": "invalid_email",
    "time": "48ms"
}
```

{% endtab %}

{% tab title="403 " %}

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

{% endtab %}

{% tab title="404 " %}

```javascript
//branch
{
    "payload": {
        "errors": [
            "branch not found"
        ]
    },
    "message": "branch not found",
    "code": "not_found",
    "time": "70ms"
}
```

{% endtab %}

{% tab title="500 " %}

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

```

{% endtab %}
{% endtabs %}

**Very (VERY) important**

> Both dates 'from' and 'to' must be specified in UTC time. For example we want 'from' date to be August 22nd 2019 at 3 p.m in Argentina. As Argentina's timezone is UTC-3, 'from' will be set as '2019-08-22 16:00:00'

{% hint style="warning" %}
optional / required body parameters

```javascript
        "anyOf": [
            {"required": ["branch_name"]},
            {"required": ["from", "to"]}
        ]
```

{% endhint %}

**Example**

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

```bash
curl -X DELETE \
  https://api.woowup.com/apiv3/purchases/bulk \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic XXXXXXXXXXXXXXXXXXXX' \
  -H 'Content-Type: application/json' \
  -d '{
	"from": "2019-07-01",
	"to": "2019-07-31",
    "notify_to": "test@email.com"
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

$payload = [
    "from" => "2019-07-01",
    "to" => "2019-07-31",
    "notify_to" => "test@noemail.com",
];

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.woowup.com/apiv3/purchases/bulk",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_HTTPHEADER => array(
    "Accept: application/json",
    "Authorization: Basic XXXXXXXXXXXXXXXXXXXX",
    "Content-Type: application/json",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="python3" %}

```python
import requests

url = "https://api.woowup.com/apiv3/purchases/bulk"

payload = {
    "from": "2019-07-01",
    "to": "2019-07-31",
    "notify_to": "test@noemail.com"
    }

headers = {
    'Accept': "application/json",
    'Authorization': "Basic XXXXXXXXXXXXXXXXXXXX",
    'Content-Type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("DELETE", url, data=payload, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

```javascript
{
    "payload": {
        "request_id": "XXX"
    },
    "message": "ok",
    "code": "ok",
    "time": "111ms"
}
```

**Practical example**

Let's say we have unwanted purchases in a certain period of time and/or assigned to a particular branch, so we wan't to delete them.\
What else do we need? An email to notify after the delete has finished and the account's Api Key ([where do I get that?](http://help.woowup.com/es/articles/2456630-mi-cuenta)).\
\
1\) First thing we are going to do is transform our start and end date to UTC time. **If you wan't to delete a whole branch's sales skip this step**.\
For example we want to delete the whole month of August 2019 in Colombia, the timezone of which is UTC-5. So the start date is 2019-08-01 00:00:00-05:00. Converted the timezone to UTC, it will be 2019-08-01 05:00:00. Then the end date converted will be 2019-09-01 04:59:59 (that is Colombia's 2019-08-31 23:59:59)\
\
2\) Now let's define the branch. **If you want to delete purchases for a period of time no matter what branch they belong to, skip this step.**\
Now we want to delete the purchases for the branch called "Example Store" ([where can I see the full list of branches?](http://help.woowup.com/es/articles/2459991-tiendas-y-zonas)). At the admin, if we open a branch, we will get the following window:

![](/files/-LmttRI9kwpFW-ZEJYgV)

What we need is the Code ("001" in this example). That is what is going to fill in the 'branch\_name' field.\
\
3\) We are ready to build and send our request. Let's say our account's apikey is "abcdefghij" and the email we want to notify after deletion is complete is "<test@example.com>". The request's cURL will go:

```bash
curl -X DELETE \
  https://api.woowup.com/apiv3/purchases/bulk \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic abcdefghij' \
  -H 'Content-Type: application/json' \
  -d '{
	"from": "2019-08-01 05:00:00",
	"to": "2019-09-01 04:59:59",
	"branch_name": "001",
    "notify_to": "test@email.com"
}'
```

*Note: if you just wan't to delete purchases for a certain period of time, ignore the 'branch\_name' field, and if you just wan't to delete a complete branch's orders, ignore 'from' and 'to' fields.*\
\
To send the request you can use any software that executes cURL commands ([Postman](https://www.getpostman.com/) for example).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://woowup-docs.gitbook.io/woowup-developer-docs/api/purchases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
