# Listar subscripciones

{% hint style="info" %}
Método: **POST**
{% endhint %}

{% hint style="success" %}
**Producción:** [https://api.payvalida.com/subscriptions/merchants/api/list/subscriptions](https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions)
{% endhint %}

{% hint style="success" %}
**Sandbox:** <https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions>
{% endhint %}

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

<table data-header-hidden data-full-width="true"><thead><tr><th width="161"></th><th width="121"></th><th></th><th></th></tr></thead><tbody><tr><td>Campo</td><td>Tipo</td><td>Requerido</td><td>Descripción</td></tr><tr><td>merchant</td><td>string</td><td>sí</td><td>Nombre asignado para el comercio en Payvalida. Se entrega con las credenciales.</td></tr><tr><td>request_id</td><td>string</td><td>sí</td><td>id de la operación de búsqueda.</td></tr><tr><td>page</td><td>string</td><td>sí</td><td>pagina de búsqueda.<br>Valor por defecto: 1<br></td></tr><tr><td>sort</td><td>string</td><td>sí</td><td>tipo de ordenamiento.<br>Valores permitidos:<br>- DESC<br>- ASC<br>Valor por Defecto: DESC </td></tr><tr><td>checksum</td><td>string</td><td>sí</td><td>Cadena de comprobación con SHA512 (merchant+request_id+ FIXED_HASH)</td></tr></tbody></table>
{% endtab %}

{% tab title="Request (ejemplo)" %}

```bash
curl --location --request POST 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions' \
--header 'Content-Type: application/json' \
--data-raw '{
    "merchant":"kuanto",
    "request_id": "123",
    "page":11,
    "sort":"DESC",
    "checksum":"e890763dc328efe31d2f626b2ab6e7c0464a09c901b3ae76ce7a5ddcba0f26a996b6626c4fc00034e82da8ff80ed843bc58a2162520b246d9c99d911a05f07aa"
}'
```

{% endtab %}

{% tab title="Response" %}

| Campo          | Estructura      | Tipo   | Descripción                                                    |
| -------------- | --------------- | ------ | -------------------------------------------------------------- |
| CODE           | -               | string | Código de respuesta **0000** para **OK.**                      |
| DESC           | -               | string | Descripción de la respuesta.                                   |
| DATA           | -               | string | Datos del registro                                             |
| subscriptions  | DATA            | struct | Estructura con la lista de subscripciones encontradas          |
| pagination     | DATA            | struct | Estructura contiene los datos referentes a la paginacion       |
| page\_num      | DATA.pagination | string | Numero de pagina entregada.                                    |
| page\_size     | DATA.pagination | string | <p>Total de registros por pagina.<br>Valor por defecto: 20</p> |
| total\_pages   | DATA.pagination | string | Cantidad de paginas existentes.                                |
| total\_results | DATA.pagination | string | Cantidad de resultados encontrados en el total de paginas.     |
|                |                 |        |                                                                |
|                |                 |        |                                                                |

{% endtab %}

{% tab title="Response (ejemplo)" %}

```json
{
    "CODE": "0000",
    "DESC": "OK",
    "DATA": {
        "subscriptions": [
            {
                "subscription_id": "977231c8-ec72-4ce9-95ff-40e704de8791",
                "created_at": "2024-02-06T14:20:41Z",
                "start_date": "06/02/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "ce664c7f-d38d-4a34-a1a9-6e831887481c",
                    "last_order_date": "2024-02-06T09:24:02.509775Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 3
                },
                "plan_id": "cdb64e45-9600-44d4-903e-e894190e25ff",
                "customer_id": "3b1fbc08-68ea-49cb-8174-9ca0297720d8",
                "customer": {
                    "customer_id": "3b1fbc08-68ea-49cb-8174-9ca0297720d8",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {
                        "token": "4121091952110001",
                        "retries": 4,
                        "franchise": "VISA",
                        "id_type": "CC",
                        "id": "100300300",
                        "holder_name": "John",
                        "holder_last_name": "Doe",
                        "email": "test@test.com",
                        "phone": "3002222222",
                        "ip": "1.1.1.1",
                        "header_user_agent": "test-user-agent",
                        "line1": "calle 22 # 22 - 22",
                        "line2": "CASA",
                        "line3": "APT",
                        "country": "Colombia",
                        "city": "Envigado",
                        "state": "Antioquia",
                        "post_code": "050001"
                    }
                }
            },
            {
                "subscription_id": "f6852229-c2b1-4fee-9a44-c2a67b70881a",
                "created_at": "2024-02-05T17:19:00Z",
                "start_date": "05/02/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "72def188-57e2-4326-a8c8-5747780b52b5",
                    "last_order_date": "2024-02-05T12:21:28.363776Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 2
                },
                "plan_id": "349b377a-fd38-41d7-bffe-6c98739caa13",
                "customer_id": "7cfb55eb-5a5c-43ca-9db4-c02362cad417",
                "customer": {
                    "customer_id": "7cfb55eb-5a5c-43ca-9db4-c02362cad417",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {
                        "token": "4119119777240001",
                        "retries": 4,
                        "franchise": "VISA",
                        "id_type": "CC",
                        "id": "100300300",
                        "holder_name": "John",
                        "holder_last_name": "Doe",
                        "email": "test@test.com",
                        "phone": "3002222222",
                        "ip": "1.1.1.1",
                        "header_user_agent": "test-user-agent",
                        "line1": "calle 22 # 22 - 22",
                        "line2": "CASA",
                        "line3": "APT",
                        "country": "Colombia",
                        "city": "Envigado",
                        "state": "Antioquia",
                        "post_code": "050001"
                    }
                }
            },
            {
                "subscription_id": "fd4be5a6-9d74-4749-9cd0-f9186f893232",
                "created_at": "2024-02-05T17:04:25Z",
                "start_date": "05/02/2024",
                "status": "ACTIVE",
                "created_orders": {
                    "last_order_id": "fb5b415f-16ab-42e3-9409-801d75eae39b",
                    "last_order_date": "2024-02-05T12:21:16.274728Z",
                    "last_order_status": "APROBADA",
                    "orders_created": 10
                },
                "plan_id": "cafdc108-850d-43fc-8804-b242c2bffd04",
                "customer_id": "636c9b8a-cb6d-42a6-b674-4f3b6a3752a3",
                "customer": {
                    "customer_id": "636c9b8a-cb6d-42a6-b674-4f3b6a3752a3",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {
                        "token": "4197236254070001",
                        "retries": 4,
                        "franchise": "VISA",
                        "id_type": "CC",
                        "id": "100300300",
                        "holder_name": "John",
                        "holder_last_name": "Doe",
                        "email": "test@test.com",
                        "phone": "3002222222",
                        "ip": "1.1.1.1",
                        "header_user_agent": "test-user-agent",
                        "line1": "calle 22 # 22 - 22",
                        "line2": "CASA",
                        "line3": "APT",
                        "country": "Colombia",
                        "city": "Envigado",
                        "state": "Antioquia",
                        "post_code": "050001"
                    }
                }
            },
            {
                "subscription_id": "08021533-ecb1-481e-b23a-145b63fb2d7f",
                "created_at": "2024-02-05T15:12:19Z",
                "start_date": "05/02/2024",
                "status": "ACTIVE",
                "created_orders": {
                    "last_order_id": "a9ac9388-b2c2-4e51-9c4e-e50bcd28511a",
                    "last_order_date": "2024-02-05T10:38:34.319404Z",
                    "last_order_status": "APROBADA",
                    "orders_created": 4
                },
                "plan_id": "9f3961ac-bfc6-4465-8a65-bed3e227290a",
                "customer_id": "09c9af0f-cab7-4bfd-b4aa-ab168f5317b1",
                "customer": {
                    "customer_id": "09c9af0f-cab7-4bfd-b4aa-ab168f5317b1",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {
                        "token": "4161657221670001",
                        "retries": 4,
                        "franchise": "VISA",
                        "id_type": "CC",
                        "id": "100300300",
                        "holder_name": "John",
                        "holder_last_name": "Doe",
                        "email": "test@test.com",
                        "phone": "3002222222",
                        "ip": "1.1.1.1",
                        "header_user_agent": "test-user-agent",
                        "line1": "calle 22 # 22 - 22",
                        "line2": "CASA",
                        "line3": "APT",
                        "country": "Colombia",
                        "city": "Envigado",
                        "state": "Antioquia",
                        "post_code": "050001"
                    }
                }
            },
            {
                "subscription_id": "71e8ce00-53cc-46a6-b4aa-997dcf53f6ba",
                "created_at": "2024-01-30T22:09:03Z",
                "start_date": "30/01/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "d0ef10d2-4568-466f-bbfe-034734db19ec",
                    "last_order_date": "2024-01-31T07:03:46.798862Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 4
                },
                "plan_id": "3e6ad2bf-386c-463b-b746-36c5ef15a888",
                "customer_id": "12cc065f-dc0b-4bfb-8701-e1626c554eba",
                "customer": {
                    "customer_id": "12cc065f-dc0b-4bfb-8701-e1626c554eba",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {
                        "token": "4187826849740001",
                        "retries": 4,
                        "franchise": "VISA",
                        "id_type": "CC",
                        "id": "100300300",
                        "holder_name": "John",
                        "holder_last_name": "Doe",
                        "email": "test@test.com",
                        "phone": "3002222222",
                        "ip": "1.1.1.1",
                        "header_user_agent": "test-user-agent",
                        "line1": "calle 22 # 22 - 22",
                        "line2": "CASA",
                        "line3": "APT",
                        "country": "Colombia",
                        "city": "Envigado",
                        "state": "Antioquia",
                        "post_code": "050001"
                    }
                }
            },
            {
                "subscription_id": "0ae60da1-9c42-42f1-9cce-e1fe06dbdc9a",
                "created_at": "2024-01-30T22:08:28Z",
                "start_date": "30/01/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "167f1ad4-8c12-497a-8571-325ee175d74b",
                    "last_order_date": "2024-01-30T17:08:32.193452Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 1
                },
                "plan_id": "3e6ad2bf-386c-463b-b746-36c5ef15a888",
                "customer_id": "c735c549-41df-4f4e-ab4f-1c9efc6c2620",
                "customer": {
                    "customer_id": "c735c549-41df-4f4e-ab4f-1c9efc6c2620",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {}
                }
            },
            {
                "subscription_id": "28532006-3fe5-4a19-b086-c7cb904e46ec",
                "created_at": "2024-01-30T21:30:01Z",
                "start_date": "30/01/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "82c6e071-bb9e-4181-aea9-90e297d3d56b",
                    "last_order_date": "2024-01-30T16:30:05.965319Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 1
                },
                "plan_id": "85d26955-c458-4217-9ff2-bc80c8301644",
                "customer_id": "ea2e480c-e805-40f4-9c49-925d41fade71",
                "customer": {
                    "customer_id": "ea2e480c-e805-40f4-9c49-925d41fade71",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {}
                }
            },
            {
                "subscription_id": "05061154-305b-4366-afe7-618226b54d93",
                "created_at": "2024-01-30T21:23:37Z",
                "start_date": "30/01/2024",
                "status": "CANCELED",
                "created_orders": {
                    "last_order_id": "88cb3bb0-2795-4dfa-8aad-2be7067f8f92",
                    "last_order_date": "2024-01-30T16:23:41.347058Z",
                    "last_order_status": "VENCIDA",
                    "orders_created": 1
                },
                "plan_id": "85d26955-c458-4217-9ff2-bc80c8301644",
                "customer_id": "00100711-328c-4712-a1c9-ffc9abf66ab0",
                "customer": {
                    "customer_id": "00100711-328c-4712-a1c9-ffc9abf66ab0",
                    "first_name": "John",
                    "last_name": "Doe",
                    "user_di": "100300300",
                    "type_di": "CC",
                    "cellphone": "+573002222222",
                    "email": "test@test.com",
                    "credit_card_data": {}
                }
            }
        ],
        "pagination": {
            "page_num": 11,
            "page_size": 20,
            "total_pages": 11,
            "total_results": 208,
            "from": 201,
            "to": 208
        }
    }
}
```

{% endtab %}

{% tab title="Cabeceras" %}

| Cabecera      | Valor            |
| ------------- | ---------------- |
| Content-Type  | application/json |
| {% endtab %}  |                  |
| {% endtabs %} |                  |

### Ejemplos

* Go

```go
package main

import (
	"bytes"
	"crypto/sha512"
	"encoding/hex"
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
)

func main() {
	url := "https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions"

	merchant := "kuanto"
	request_id := "month"
	page := 1
	sort := "DESC"
	fixedHash := "FIXED_HASH"

	checksum := createChecksum(merchant, request_id, fixedHash)

	payload := []byte(fmt.Sprintf(`{
		"merchant": "%s",
		"request_id": "%s",
		"page": "%s",
		"sort": "%s",
		"checksum":"%s",
	}`, merchant, request_id, page, sort, checksum))

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}

	defer resp.Body.Close()

	// Read response body
	responseData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response body:", err)
		return
	}

	// Print response data
	fmt.Println("Response:", string(responseData))
}

func createChecksum(merchant, request_id, fixedHash string) string {
	checksumData := merchant + request_id + fixedHash
	hash := sha512.Sum512([]byte(checksumData))
	checksum := hex.EncodeToString(hash[:])
	return checksum
}

```

* PHP

<pre class="language-php"><code class="lang-php">&#x3C;?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json'
];

$url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions';
$merchant = 'kuanto';
<strong>$request_id = '123';
</strong>$page = 1; 
$sort = 'DESC';
$fixedHash = 'FIXED_HASH';

$checksum = createChecksum($merchant, $request_id, $fixedHash);

$body = '{
  "merchant": $merchant,
  "request_id": $request_id,
  "page": $page,
  "sort": $sort,
  "checksum": $checksum
}';
$request = new Request('POST', $url, $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

function createChecksum($merchant, $request_id, $fixedHash)
{
    $checksumData = $merchant . $request_id . $fixedHash;
    $checksum = hash('sha512', $checksumData);
    return $checksum;
}
?>
</code></pre>

* Javascript

```javascript
const fetch = require('node-fetch');
const crypto = require('crypto');

const url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions';
const merchant = 'kuanto';
const request_id = 'month';
const page = 1;
const sort = 'DESC';
const fixedHash = 'FIXED_HASH';

const checksumData = merchant + request_id + fixedHash;
const checksum = crypto.createHash('sha512').update(checksumData).digest('hex');

const payload = JSON.stringify({
merchant,
request_id,
page,
sort,
checksum
});

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: payload,
})
.then(response => response.text())
.then(body => {
console.log('Response:', body);
})
.catch(error => {
console.error('Error sending request:', error);
});
```

* Java

```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static void main(String[] args) {
        String url = "https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions";
        String merchant = "kuanto";
        String request_id = "123";
        String page = 1;
        String sort = "DESC";
        String fixedHash = "FIXED_HASH";

        String checksum = createChecksum(merchant, request_id, fixedHash);

        String payload = String.format("{\"merchant\": \"%s\", \"request_id\": \"%s\", \"page\": %n, \"sort\": \"%s\", \"checksum\": \"%s\"}",
                merchant, request_id, page, sort, checksum);

        try {
            URL requestUrl = new URL(url);
            HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setDoOutput(true);

            try (OutputStream outputStream = connection.getOutputStream()) {
                byte[] input = payload.getBytes(StandardCharsets.UTF_8);
                outputStream.write(input, 0, input.length);
            }

            int responseCode = connection.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                    String line;
                    StringBuilder response = new StringBuilder();
                    while ((line = reader.readLine()) != null) {
                        response.append(line);
                    }
                    System.out.println("Response: " + response.toString());
                }
            } else {
                System.out.println("Error: " + responseCode);
            }

            connection.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String createChecksum(String merchant, String request_id, String fixedHash) {
        String checksumData = merchant + request_id + fixedHash;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-512");
            byte[] hashBytes = digest.digest(checksumData.getBytes(StandardCharsets.UTF_8));
            StringBuilder hexString = new StringBuilder();
            for (byte hashByte : hashBytes) {
                String hex = Integer.toHexString(0xff & hashByte);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}

```

* Python

```python
import requests
import hashlib
import json
import time

url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions'
merchant = 'kuanto'
request_id = '123'
page = 1
sort = 'DESC'
fixed_hash = 'FIXED_HASH'


checksum_data = merchant + request_id + fixed_hash
checksum = hashlib.sha512(checksum_data.encode()).hexdigest()

payload = {
    'merchant': merchant,
    'request_id': request_id,
    'page': page,
    'sort': sort,
    'checksum': checksum
}

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    print('Response:', response.text)
else:
    print('Error:', response.status_code)

```


---

# 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://docs.payvalida.com/api-suscripciones/visualizacion-de-subscripciones/listar-subscripciones.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.
