# השלמת העלאת נכס

כתובת URL קנונית: https://sosoapi.ai/he/docs/api/assets-api-upload-complete

Contract: sha256:563d2d581da0ad29

רישום הקובץ לאחר סיום העלאתו. השתמשו בפרטי האובייקט שהוחזרו מ-upload/sign ושמרו על אותו מפתח אידמפוטנטיות בניסיון חוזר.

POST /assets-api/upload/complete

## אימות והרשאות

- **סוגי אמצעי גישה מתקבלים:** user_session, delegated_oauth, personal_access_token

- **יכולת מואצלת:** agent:operate

- **תפקיד מינימלי בסביבת העבודה:** editor

- **היקף הגישה:** משאבים שהמשתמש הזה מורשה לגשת אליהם

- **נדרשת הסכמה לכל סביבות העבודה:** לא

- **משנה מצב:** כן

- **מתי הפעולה הושלמה:** synchronous_http_response

אסימון יכול להשתמש רק בזכויות שיש לבעליו. כל בקשה בודקת חברות בסביבת העבודה, בעלות על משאבים, סביבות עבודה נבחרות ויכולות שהוענקו. הפרופילים core ו-full משנים אילו כלים מוצגים; הם אינם מעניקים גישה.

## שדות הבקשה

```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
}
```

## תגובה והשלמה

סטטוסי HTTP להצלחה: 200

תגובת HTTP מוצלחת עשויה לציין שבקשה התקבלה, ולא שהושלמה. בעבודת רקע, שמרו את המזהה שהוחזר ובדקו את אותה פעולה עד שתסתיים. פוסט שתוזמן או התקבל נחשב שפורסם רק כשהפלטפורמה מאשרת זאת; חריגה מזמן ההמתנה אצל הלקוח אינה קובעת מה התוצאה.

```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"
  ]
}
```

## שגיאות וניסיונות חוזרים בטוחים

בדקו את סטטוס ה-HTTP ואת גוף התגובה. שגיאת אימות 400 עשויה להכיל ZodError; שגיאות מטפל משתמשות בשדות error, ‏message ו-code. שמרו request_id או x-request-id לאבחון, ללא אמצעי גישה. תקנו שגיאות גישה 401/403 לפני ניסיון חוזר, ופעלו לפי Retry-After עבור 429. אם תוצאת כתיבה אינה ודאית או שמוחזר 5xx, קראו תחילה את התוצאה הקיימת. השתמשו שוב במפתח אידמפוטנטיות רק במקומות הנתמכים; התנהגות הניסיון החוזר משתנה בין פעולות ואינה מבטיחה מסירה בדיוק פעם אחת.

## דוגמאות

הדוגמאות משתמשות בערכים בדויים שנבדקו מול הסכמות. החליפו את המזהים בכאלה שאתם מורשים להשתמש בהם, את המדיה בנכסים מוכנים ואת התאריכים במועד הפרסום שאישרתם. בדקו את התאמת החשבון לפני שליחת כתיבה. העמוד הזה אינו שולח בקשות API.

הגדירו בשרת שלכם SOSOAPI_ACCESS_TOKEN לאמצעי גישה שהפעולה הזו מקבלת, והשאירו אותו מחוץ לקוד הדפדפן. עבור סוכן, השתמשו ב-sosoapi auth login כדי להיכנס דרך הדפדפן ולאפשר ל-CLI לרענן את אמצעי הגישה שלו.

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
```

דוגמת תגובה סינתטית

```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
}
```

## כלים ומדריכים קשורים

MCP: sosoapi_upload_asset

[תיעוד API](https://sosoapi.ai/he/docs/api)
