# Completar la carga de un recurso

URL canónica: https://sosoapi.ai/es/docs/api/assets-api-upload-complete

Contrato: sha256:563d2d581da0ad29

Registra el archivo cuando termine la carga. Usa los datos del objeto devueltos por upload/sign y conserva la misma clave de idempotencia al reintentar.

POST /assets-api/upload/complete

## Autenticación y permisos

- **Clases de credenciales aceptadas:** user_session, delegated_oauth, personal_access_token

- **Capacidad delegada:** agent:operate

- **Rol mínimo del espacio de trabajo:** editor

- **Alcance del acceso:** Recursos a los que este usuario está autorizado a acceder

- **Se requiere consentimiento para todos los espacios de trabajo:** No

- **Cambia el estado:** Sí

- **Cuando la operación se completa:** synchronous_http_response

Un token solo puede usar los derechos de su propietario. Cada solicitud comprueba pertenencia al espacio, propiedad del recurso, espacios elegidos y capacidades concedidas. Los perfiles core y full cambian qué herramientas se muestran; no conceden acceso.

## Campos de solicitud

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "workspace_id": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "asset_type": {
      "type": "string",
      "enum": [
        "image",
        "video"
      ]
    },
    "object_key": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512
    },
    "content_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "title": {
      "type": "string",
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "maxLength": 2000
    },
    "tags": {
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 64
      }
    },
    "metadata": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {},
      "description": "Free-form JSON object; its serialized UTF-8 size must not exceed 16384 bytes."
    },
    "source": {
      "default": "mcp_upload",
      "type": "string",
      "maxLength": 64
    },
    "source_metadata": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {},
      "description": "Free-form JSON object; its serialized UTF-8 size must not exceed 16384 bytes."
    },
    "idempotency_key": {
      "type": "string",
      "minLength": 8,
      "maxLength": 160
    }
  },
  "required": [
    "workspace_id",
    "asset_type",
    "object_key",
    "content_sha256"
  ],
  "additionalProperties": false
}
```

## Respuesta y finalización

Estados HTTP de éxito: 200

Una respuesta HTTP exitosa puede indicar aceptación, no finalización. Para trabajo en segundo plano, guarda el ID devuelto y consulta la misma operación hasta que termine. Una publicación programada o aceptada solo está publicada cuando la plataforma lo confirma; un tiempo de espera agotado en el cliente no determina el resultado.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "asset": {
      "type": "object",
      "properties": {
        "id": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string"
            }
          ]
        },
        "workspace_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        "user_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        "asset_type": {
          "type": "string",
          "enum": [
            "text",
            "image",
            "video",
            "audio"
          ]
        },
        "asset_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "preview_url": {
          "description": "Workspace-authorized temporary read URL. Refresh through Asset read/list after preview_expires_at; keep asset_url as persisted media identity.",
          "anyOf": [
            {
              "type": "string",
              "format": "uri"
            },
            {
              "type": "null"
            }
          ]
        },
        "preview_expires_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$"
            },
            {
              "type": "null"
            }
          ]
        },
        "title": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "tags": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "metadata": {
          "anyOf": [
            {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {}
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "source_metadata": {
          "anyOf": [
            {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {}
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "string"
        },
        "version": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "id",
        "workspace_id",
        "user_id",
        "asset_type",
        "asset_url",
        "title",
        "description",
        "tags",
        "metadata",
        "created_at"
      ]
    },
    "deduped": {
      "type": "boolean"
    }
  },
  "required": [
    "asset",
    "deduped"
  ]
}
```

## Errores y reintentos seguros

Comprueba el estado HTTP y el cuerpo de respuesta. Un error de validación 400 puede contener un ZodError; los errores del controlador usan los campos error, message y code. Conserva request_id o x-request-id para el diagnóstico, sin credenciales. Corrige los errores de acceso 401/403 antes de reintentar y respeta Retry-After para 429. Si una escritura es incierta o devuelve 5xx, consulta primero el resultado existente. Reutiliza una clave de idempotencia solo donde se admita; el comportamiento de reintento varía por operación y no garantiza una entrega exactamente una vez.

## Ejemplos

Estos ejemplos usan valores ficticios comprobados con los esquemas. Sustituye los IDs por otros autorizados, los archivos multimedia por recursos listos y las fechas por tu hora de publicación confirmada. Comprueba la elegibilidad de la cuenta antes de enviar una escritura. Esta página no envía solicitudes API.

Establece SOSOAPI_ACCESS_TOKEN en tu servidor con una credencial aceptada por esta operación y mantenla fuera del código del navegador. Para un agente, usa sosoapi auth login para iniciar sesión en el navegador y deja a la CLI renovar sus credenciales.

request.json

```json
{
  "workspace_id": "11111111-1111-4111-8111-111111111111",
  "asset_type": "image",
  "object_key": "workspaces/11111111-1111-4111-8111-111111111111/image/example.png",
  "content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "idempotency_key": "example-upload-0001"
}
```

cURL

```bash
curl --request POST \
  "https://gqeshlawtcexsapabaui.supabase.co/functions/v1/assets-api/upload/complete" \
  -H "Authorization: Bearer $SOSOAPI_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @request.json
```

JavaScript

```js
// Server-side JavaScript. Do not print tokens or credential-bearing responses.
const token = process.env.SOSOAPI_ACCESS_TOKEN;
if (!token) throw new Error("Set an accepted credential for this operation");
const response = await fetch("https://gqeshlawtcexsapabaui.supabase.co/functions/v1/assets-api/upload/complete", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: "Bearer " + token },
  body: JSON.stringify({
  "workspace_id": "11111111-1111-4111-8111-111111111111",
  "asset_type": "image",
  "object_key": "workspaces/11111111-1111-4111-8111-111111111111/image/example.png",
  "content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "idempotency_key": "example-upload-0001"
})
});
const result = await response.json();
// Check response.ok, the operation-specific body and completion state before continuing.
```

CLI

```bash
npx sosoapi api post /assets-api/upload/complete < request.json
```

Ejemplo de respuesta sintética

```json
{
  "asset": {
    "id": 0,
    "workspace_id": "11111111-1111-4111-8111-111111111111",
    "user_id": "11111111-1111-4111-8111-111111111111",
    "asset_type": "text",
    "asset_url": null,
    "title": null,
    "description": null,
    "tags": null,
    "metadata": null,
    "created_at": "example"
  },
  "deduped": false
}
```

## Herramientas y guías relacionadas

MCP: sosoapi_upload_asset

[Referencia de API](https://sosoapi.ai/es/docs/api)
