Asana: Upload an attachment
Asana attachments.createAttachmentForObject: arguments, response, policy and SDK examples.
← Attachments operations · Get started
Operation asana.createattachmentforobject
Provider route: POST /attachments. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”Install @alter-ai/sdk @alter-ai/asana with npm, or alter-sdk-asana with pip. Supply your connected customer’s grant ID and the arguments described below.
import { App } from "@alter-ai/sdk";import { AsanaIntegration } from "@alter-ai/asana";
async function execute(input: Parameters<AsanaIntegration["attachments"]["createAttachmentForObject"]>[0]) { const app = new App({ apiKey: process.env.ALTER_API_KEY! }); try { const provider = new AsanaIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! }); const call = await provider.attachments.createAttachmentForObject(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom alter_sdk_asana import AsanaIntegration
async def execute(arguments): async with App(api_key=os.environ["ALTER_API_KEY"]) as app: provider = AsanaIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]}) call = await provider.attachments.create_attachment_for_object(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
query | object | Optional | Additional keys: not allowed |
query.opt_pretty | boolean | Optional | |
query.opt_fields | array | Optional | |
query.opt_fields[] | string | Each item | One of: connected_to_app, created_at, download_url, host, name, parent, parent.created_by, parent.name, parent.resource_subtype, permanent_url, resource_subtype, size, view_url |
body | object | Optional | |
body.resource_subtype | string | Optional | The type of the attachment. Must be one of the given values. If not specified, a file attachment of type `asana` will be assumed. Note that if the value of `resource_subtype` is `external`, a `parent`, `name`, and `url` must also be provided. One of: asana, external |
body.file | object | Optional | Required for `asana` attachments. Additional keys: not allowed |
body.file.filename | string | Required within parent | Minimum length: 1 |
body.file.content_type | string | Required within parent | Minimum length: 1 |
body.file.content_base64 | string | Required within parent | |
body.parent | string | Required within parent | Required identifier of the parent task, project, or project_brief, as a string. |
body.url | string | Optional | The URL of the external resource being attached. Required for attachments of type `external`. |
body.name | string | Optional | The name of the external resource being attached. Required for attachments of type `external`. |
body.connect_to_app | boolean | Optional | Optional. Only relevant for external attachments with a parent task. A boolean indicating whether the current app should be connected with the attachment for the purposes of showing an app components widget. Requires the app to have been added to a project the parent task is in. This property can only be set if an OAuth token is used to authenticate the request. Criteria for displaying app widget: 1. An OAuth token must be used to authenticate the request 2. The app needs to have its `widget_metadata_url` configured in the developer console 3. The task the attachment is being attached to must be in a project with the app installed |
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | JSON | Root | |
$ (allOf 1) | object | All variants apply | |
$ (allOf 1).data | Model | Optional | Expand Get an attachment — response body — data data — Attachment Response |
$ (allOf 2) | Model | All variants apply | Expand Get an attachment — response body — data |
Referenced models: Get an attachment — response body — data data — Attachment Response, Get an attachment — response body — data
Schemas
Section titled “Schemas”1 more schema is linked from the tables above, on the schema pages.
Get an attachment — response body — data data — Attachment Response
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | JSON | Root | |
$ (allOf 1) | Model | All variants apply | Expand Get attachments from an object — response body — data, next page data item |
$ (allOf 2) | object | All variants apply | |
$ (allOf 2).created_at | string | Optional | The time at which this resource was created. Format: date-time Read only: true |
$ (allOf 2).download_url | JSON | Optional | |
$ (allOf 2).download_url (anyOf 1) | string | Alternative | The URL containing the content of the attachment. *Note:* May be null if the attachment is hosted by [Box](https://www.box.com/) and will be null if the attachment is a Video Message hosted by [Vimeo](https://vimeo.com/). If present, this URL may only be valid for two minutes from the time of retrieval. You should avoid persisting this URL somewhere and just refresh it on demand to ensure you do not keep stale URLs. Format: uri Read only: true |
$ (allOf 2).download_url (anyOf 2) | null | Alternative | |
$ (allOf 2).permanent_url | JSON | Optional | |
$ (allOf 2).permanent_url (anyOf 1) | string | Alternative | A stable URL for accessing the attachment through the Asana web application. This URL redirects to the file download location (e.g., an S3 link) if the user is authenticated and authorized to view the parent object (e.g., a task). Unauthorized users will receive a `403 Forbidden` response. This link is persistent and does not expire, but requires an active session to resolve. Format: uri Read only: true |
$ (allOf 2).permanent_url (anyOf 2) | null | Alternative | |
$ (allOf 2).host | string | Optional | The service hosting the attachment. Valid values are `asana`, `dropbox`, `gdrive`, `onedrive`, `box`, `vimeo`, and `external`. Read only: true |
$ (allOf 2).parent | JSON | Optional | |
$ (allOf 2).parent (anyOf 1) | JSON | Alternative | |
$ (allOf 2).parent (anyOf 1) (allOf 1) | Model | All variants apply | Expand Search tasks in a workspace — response body — data data item |
$ (allOf 2).parent (anyOf 1) (allOf 2) | object | All variants apply | The task this attachment is attached to. Read only: true |
$ (allOf 2).parent (anyOf 1) (allOf 2).resource_subtype | JSON | Optional | |
$ (allOf 2).parent (anyOf 1) (allOf 2).resource_subtype (anyOf 1) | string | Alternative | The resource subtype of the parent resource that the filter applies to. |
$ (allOf 2).parent (anyOf 1) (allOf 2).resource_subtype (anyOf 2) | null | Alternative | |
$ (allOf 2).parent (anyOf 2) | null | Alternative | |
$ (allOf 2).size | JSON | Optional | |
$ (allOf 2).size (anyOf 1) | integer | Alternative | The size of the attachment in bytes. Only present when the `resource_subtype` is `asana`. Read only: true |
$ (allOf 2).size (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
$ (allOf 2).view_url | JSON | Optional | |
$ (allOf 2).view_url (anyOf 1) | string | Alternative | The URL where the attachment can be viewed, which may be friendlier to users in a browser than just directing them to a raw file. May be null if no view URL exists for the service. Format: uri Read only: true |
$ (allOf 2).view_url (anyOf 2) | null | Alternative | |
$ (allOf 2).connected_to_app | boolean | Optional | Whether the attachment is connected to the app making the request for the purposes of showing an app components widget. Only present when the `resource_subtype` is `external` or `gdrive`. Read only: true |
Referenced models: Get attachments from an object — response body — data, next page data item, Search tasks in a workspace — response body — data data item
Get an attachment — response body — data
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | |
data | Model | Required within parent | Expand Get an attachment — response body — data data — sdk__Attachment Response |
Referenced models: Get an attachment — response body — data data — sdk__Attachment Response
Get attachments from an object — response body — data, next page data item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | An *attachment* object represents any file attached to a task in Asana, whether it's an uploaded file or one associated via a third-party service such as Dropbox or Google Drive. |
gid | string | Optional | Globally unique identifier of the resource, as a string. Read only: true |
resource_type | string | Optional | The base type of this resource. Read only: true |
name | string | Optional | The name of the file. Read only: true |
resource_subtype | string | Optional | The service hosting the attachment. Valid values are `asana`, `dropbox`, `gdrive`, `onedrive`, `box`, `vimeo`, and `external`. |
Search tasks in a workspace — response body — data data item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | The *task* is the basic object around which many operations in Asana are centered. |
gid | string | Optional | Globally unique identifier of the resource, as a string. Read only: true |
resource_type | string | Optional | The base type of this resource. Read only: true |
name | string | Optional | The name of the task. |
resource_subtype | string | Optional | The subtype of this resource. Different subtypes retain many of the same fields and behavior, but may render differently in Asana or represent resources with different semantic meaning. The resource_subtype `milestone` represent a single moment in time. This means tasks with this subtype cannot have a start_date. Known values: default_task, milestone, approval, custom |
created_by | object | Optional | [Opt In](/docs/inputoutput-options). A *user* object represents an account in Asana that can be given access to various workspaces, projects, and tasks. Read only: true |
created_by.gid | string | Optional | Globally unique identifier of the resource. |
created_by.resource_type | string | Optional | The type of resource. |
Get an attachment — response body — data data — sdk__Attachment Response
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A generic Asana Resource, containing a globally unique identifier.A generic Asana Resource, containing a globally unique identifier. An *attachment* object represents any file attached to a task in Asana, whether it's an uploaded file or one associated via a third-party service such as Dropbox or Google Drive. |
gid | string | Optional | Globally unique identifier of the resource, as a string. Read only: true |
resource_type | string | Optional | The base type of this resource. Read only: true |
name | string | Optional | The name of the file. Read only: true |
resource_subtype | string | Optional | The service hosting the attachment. Valid values are `asana`, `dropbox`, `gdrive`, `onedrive`, `box`, `vimeo`, and `external`. |
created_at | string | Optional | The time at which this resource was created. Format: date-time Read only: true |
download_url | JSON | Optional | |
download_url (anyOf 1) | string | Alternative | The URL containing the content of the attachment. *Note:* May be null if the attachment is hosted by [Box](https://www.box.com/) and will be null if the attachment is a Video Message hosted by [Vimeo](https://vimeo.com/). If present, this URL may only be valid for two minutes from the time of retrieval. You should avoid persisting this URL somewhere and just refresh it on demand to ensure you do not keep stale URLs. Format: uri Read only: true |
download_url (anyOf 2) | null | Alternative | |
permanent_url | JSON | Optional | |
permanent_url (anyOf 1) | string | Alternative | A stable URL for accessing the attachment through the Asana web application. This URL redirects to the file download location (e.g., an S3 link) if the user is authenticated and authorized to view the parent object (e.g., a task). Unauthorized users will receive a `403 Forbidden` response. This link is persistent and does not expire, but requires an active session to resolve. Format: uri Read only: true |
permanent_url (anyOf 2) | null | Alternative | |
host | string | Optional | The service hosting the attachment. Valid values are `asana`, `dropbox`, `gdrive`, `onedrive`, `box`, `vimeo`, and `external`. Read only: true |
parent | JSON | Optional | |
parent (anyOf 1) | Model | Alternative | Expand Get an attachment — response body — data data parent created by, gid, name, resource subtype, resource type |
parent (anyOf 2) | null | Alternative | |
size | JSON | Optional | |
size (anyOf 1) | integer | Alternative | The size of the attachment in bytes. Only present when the `resource_subtype` is `asana`. Read only: true |
size (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
view_url | JSON | Optional | |
view_url (anyOf 1) | string | Alternative | The URL where the attachment can be viewed, which may be friendlier to users in a browser than just directing them to a raw file. May be null if no view URL exists for the service. Format: uri Read only: true |
view_url (anyOf 2) | null | Alternative | |
connected_to_app | boolean | Optional | Whether the attachment is connected to the app making the request for the purposes of showing an app components widget. Only present when the `resource_subtype` is `external` or `gdrive`. Read only: true |
Referenced models: Get an attachment — response body — data data parent created by, gid, name, resource subtype, resource type
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: asana.createattachmentforobject. Catalog operation: asana:createAttachmentForObject. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.
Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.
Required provider scopes: ["attachments:write"]