{
  "info": {
    "name": "STCP DirectLink API v2 (es) — versión 9",
    "description": "Llamadas de la API REST de STCP DirectLink 9. Complete las variables baseUrl, username y password. \"Obtener token (password grant)\" guarda el token en la variable token, que usan las rutas protegidas (Authorization: Bearer). A partir de la versión 9, la carga, los listados, el informe y el cierre de sesión no aceptan Basic. Los listados guardan el linkURL del primer archivo en fileLink y backupFileLink; el inicio de sesión con MFA guarda el enlace del desafío en mfaLink. Habilite el header CF-Turnstile-Response solo si el entorno exige Cloudflare Turnstile.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{token}}",
        "type": "string"
      }
    ]
  },
  "item": [
    {
      "name": "Disponibilidad",
      "item": [
        {
          "name": "Health check",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/healthcheck",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "healthcheck"
              ]
            },
            "auth": {
              "type": "noauth"
            }
          }
        }
      ]
    },
    {
      "name": "Autenticación",
      "item": [
        {
          "name": "Obtener token (password grant)",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/oauth2/token",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "oauth2",
                "token"
              ]
            },
            "auth": {
              "type": "noauth"
            },
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "password"
                },
                {
                  "key": "username",
                  "value": "{{username}}"
                },
                {
                  "key": "password",
                  "value": "{{password}}"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const r = pm.response.json();",
                  "if (r.access_token) { pm.collectionVariables.set('token', r.access_token); }"
                ]
              }
            }
          ]
        },
        {
          "name": "Obtener token (token exchange)",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/auth/token",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "token"
              ]
            },
            "auth": {
              "type": "noauth"
            },
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "urn:ietf:params:oauth:grant-type:token-exchange"
                },
                {
                  "key": "subject_token_type",
                  "value": "urn:ietf:params:oauth:token-type:jwt"
                },
                {
                  "key": "subject_token",
                  "value": "{{subjectToken}}",
                  "description": "JWT emitido por el proveedor de origen"
                },
                {
                  "key": "provider",
                  "value": "{{provider}}",
                  "description": "Identificador del proveedor JWT registrado"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const r = pm.response.json();",
                  "if (r.access_token) { pm.collectionVariables.set('token', r.access_token); }"
                ]
              }
            }
          ]
        },
        {
          "name": "Inicio de sesión local (Basic)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "CF-Turnstile-Response",
                "value": "{{turnstileToken}}",
                "description": "Token de Cloudflare Turnstile (solo si el entorno lo exige)",
                "disabled": true
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/auth/login",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "login"
              ]
            },
            "auth": {
              "type": "basic",
              "basic": [
                {
                  "key": "username",
                  "value": "{{username}}",
                  "type": "string"
                },
                {
                  "key": "password",
                  "value": "{{password}}",
                  "type": "string"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 206) { const r = pm.response.json(); if (r.linkURL) { pm.collectionVariables.set('mfaLink', r.linkURL); } }"
                ]
              }
            }
          ]
        },
        {
          "name": "Completar MFA",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{mfaLink}}"
            },
            "auth": {
              "type": "noauth"
            },
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "p",
                  "value": "",
                  "description": "PIN o código TOTP"
                }
              ]
            },
            "description": "Use el linkURL devuelto en el 206 del inicio de sesión (guardado en mfaLink)"
          }
        },
        {
          "name": "Cerrar sesión",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/auth/logout",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "logout"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Contraseña",
      "item": [
        {
          "name": "Primer acceso",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "CF-Turnstile-Response",
                "value": "{{turnstileToken}}",
                "description": "Token de Cloudflare Turnstile (solo si el entorno lo exige)",
                "disabled": true
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/auth/firstaccess?u={{username}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "firstaccess"
              ],
              "query": [
                {
                  "key": "u",
                  "value": "{{username}}",
                  "description": "Usuario registrado en la plataforma"
                }
              ]
            },
            "auth": {
              "type": "noauth"
            }
          }
        },
        {
          "name": "Olvidé mi contraseña",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "CF-Turnstile-Response",
                "value": "{{turnstileToken}}",
                "description": "Token de Cloudflare Turnstile (solo si el entorno lo exige)",
                "disabled": true
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/auth/forget?u={{username}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "forget"
              ],
              "query": [
                {
                  "key": "u",
                  "value": "{{username}}",
                  "description": "Usuario registrado en la plataforma"
                }
              ]
            },
            "auth": {
              "type": "noauth"
            }
          }
        },
        {
          "name": "Cambio de contraseña",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{passwordLink}}"
            },
            "auth": {
              "type": "noauth"
            },
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "p",
                  "value": "",
                  "description": "PIN enviado al usuario"
                },
                {
                  "key": "z",
                  "value": "",
                  "description": "Nueva contraseña"
                }
              ]
            },
            "description": "Guarde en passwordLink el enlace seguro recibido por el usuario"
          }
        }
      ]
    },
    {
      "name": "Transferencias",
      "item": [
        {
          "name": "Carga multipart",
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/upload",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "upload"
              ]
            },
            "body": {
              "mode": "formdata",
              "formdata": [
                {
                  "key": "file",
                  "type": "file",
                  "src": "",
                  "description": "Archivo que se enviará"
                },
                {
                  "key": "d",
                  "value": "",
                  "type": "text",
                  "description": "Usuario de destino (opcional)"
                },
                {
                  "key": "m",
                  "value": "",
                  "type": "text",
                  "description": "Correo del destinatario del enlace (opcional)"
                },
                {
                  "key": "c",
                  "value": "",
                  "type": "text",
                  "description": "Celular del destinatario del enlace (opcional)"
                },
                {
                  "key": "h",
                  "value": "",
                  "type": "text",
                  "description": "Hash SHA-256 hexadecimal del archivo (opcional)"
                },
                {
                  "key": "n",
                  "value": "",
                  "type": "text",
                  "description": "Correo o identificación del remitente (opcional)"
                },
                {
                  "key": "i",
                  "value": "",
                  "type": "text",
                  "description": "Información adicional o mensaje (opcional)"
                }
              ]
            }
          }
        },
        {
          "name": "Carga binaria",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/octet-stream"
              },
              {
                "key": "X-STCPDIRECTLINK-FILENAME",
                "value": "",
                "description": "Nombre del archivo"
              },
              {
                "key": "X-STCPDIRECTLINK-DESTINATION",
                "value": "",
                "description": "Usuario de destino (opcional)"
              },
              {
                "key": "X-STCPDIRECTLINK-EMAIL",
                "value": "",
                "description": "Correo del destinatario del enlace (opcional)"
              },
              {
                "key": "X-STCPDIRECTLINK-MOBILE",
                "value": "",
                "description": "Celular del destinatario del enlace (opcional)"
              },
              {
                "key": "X-STCPDIRECTLINK-HASH",
                "value": "",
                "description": "Hash SHA-256 hexadecimal del archivo (opcional)"
              },
              {
                "key": "X-STCPDIRECTLINK-EMAIL-FROM",
                "value": "",
                "description": "Correo o identificación del remitente (opcional)"
              },
              {
                "key": "X-STCPDIRECTLINK-INFO",
                "value": "",
                "description": "Información adicional o mensaje (opcional)"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/upload",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "upload"
              ]
            },
            "body": {
              "mode": "file",
              "file": {
                "src": ""
              }
            }
          }
        },
        {
          "name": "Lista de archivos para descarga",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/download/list?page=0",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "download",
                "list"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "0",
                  "description": "Página, a partir de 0"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const r = pm.response.json();",
                  "if (r.files && r.files.length) { pm.collectionVariables.set('fileLink', r.files[0].linkURL); }"
                ]
              }
            }
          ]
        },
        {
          "name": "Lista de archivos del backup",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/download/list/backup?page=0",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "download",
                "list",
                "backup"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "0",
                  "description": "Página, a partir de 0"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const r = pm.response.json();",
                  "if (r.files && r.files.length) { pm.collectionVariables.set('backupFileLink', r.files[0].linkURL); }"
                ]
              }
            }
          ]
        },
        {
          "name": "Descarga del archivo",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{fileLink}}"
            },
            "auth": {
              "type": "noauth"
            },
            "description": "linkURL guardado por el listado (fileLink)"
          }
        },
        {
          "name": "Descarga del archivo del backup",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{backupFileLink}}"
            },
            "auth": {
              "type": "noauth"
            },
            "description": "linkURL guardado por el listado del backup (backupFileLink)"
          }
        }
      ]
    },
    {
      "name": "Informe",
      "item": [
        {
          "name": "Informe de transferencias",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/report?filterdirection=7&days=7&page=0",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "report"
              ],
              "query": [
                {
                  "key": "filterdirection",
                  "value": "7",
                  "description": "5 = descargas concluidas; 7 = cargas concluidas"
                },
                {
                  "key": "days",
                  "value": "7",
                  "description": "Período en días"
                },
                {
                  "key": "page",
                  "value": "0",
                  "description": "Página, a partir de 0"
                },
                {
                  "key": "filterfile",
                  "value": "",
                  "description": "Parte del nombre del archivo (opcional)",
                  "disabled": true
                }
              ]
            }
          }
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://<dominio>/directlink/v2"
    },
    {
      "key": "username",
      "value": ""
    },
    {
      "key": "password",
      "value": ""
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "turnstileToken",
      "value": ""
    },
    {
      "key": "subjectToken",
      "value": ""
    },
    {
      "key": "provider",
      "value": ""
    },
    {
      "key": "mfaLink",
      "value": ""
    },
    {
      "key": "passwordLink",
      "value": ""
    },
    {
      "key": "fileLink",
      "value": ""
    },
    {
      "key": "backupFileLink",
      "value": ""
    }
  ]
}
