Can post attachment, but cannot GET attachments

Following example code:

const projectGID = ‘1171144249301681’;

const statusResult = await asanaClient.projectStatuses.createProjectStatusForProject(
projectGID,
{
color: ‘green’,
text: ‘test’,
title: ‘test title’
}
);
console.log(‘statusResult’, statusResult);

We created a new status update,
to ensure all is good, we fetch it now again:

const statusUpdate = await asanaClient.projectStatuses.getProjectStatus(
statusResult.gid
);

console.log(‘statusUpdate’, statusUpdate);
all good, we have a new status update in place.

great, now we add an attachment:

const paramsUpload = {
method: ‘POST’,
url: https://app.asana.com/api/1.0/tasks/${statusUpdate.gid}/attachments,
formData: {
file: {
value: fs.readFileSync(‘img.jpg’),
options: {
filename: ‘test’
}
}
},
headers: {
‘Content-Type’: ‘multipart/form-data’
}
};
await asanaClient.dispatcher.dispatch(paramsUpload, {});

wow, also this worked! You can see the attachment in the status update now :slight_smile: perfect!

And now we want to get all attachments that are assoicated with this status update:

const params = {
method: ‘GET’,
url: https://app.asana.com/api/1.0/tasks/${statusUpdate.gid}/attachments
};
const res = await asanaClient.dispatcher.dispatch(params, {});

or via client direclty:

const res = await asanaClient.attachments
.getAttachmentsForTask(statusUpdate.gid);

:frowning: … not working … Api says it does not recognize the ID?
{“errors”:[{“message”:“task: Not a recognized ID: 1198849200704702”,“help”:“For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors”}]}

Uploading works with the GID though, therefore I assume this is an API bug!?

Thanks
Simon

You are using getAttachmentsForTask to get attachments for a status, don’t you? That does not seem right.

Yes, but it works for uploads, therefore i thought the status update is probably a “task” in the background too…? But no idea about the backend, just guessing and trying (as we do with a lot of apis ;-))

No, project status update is its own unique object type.

1 Like

Yeah I see what you mean, the API doc says so… right, but why it works for uploads? Can’t we just add the ability to also work for status updates, like it is in “add attachments” (POST /tasks/{taskId}/attachments) to the very similar endpoint (GET /tasks/{taskId}/attachments)?

Good question! That is indeed surprising.

@Ross_Grambo any thoughts on how to get attachments from a project status update?

This is surprising to me too… I’ll send it as a bug for the API team for their input.

3 Likes

In short, it sounds like POST https://app.asana.com/api/1.0/tasks/${statusUpdate.gid}/attachments gets converted into something like: attachment on parent ${statusUpdate.gid}. This is why this endpoint works, because the /task/ isn’t really relevant.

However when you GET, it follows a different code path that does care about the /tasks/ part of the url.

The current state is: We don’t officially support posting or getting attachments on status_updates yet. The API team just added this to their backlog.

2 Likes