Trello cards attachments edit

Hi everyone. My question is probably a little stupid. But can you help me to find a way to edit a link of existing Trello card’s attachment? Actually, I need to change a url of attachment.
I haven’t found API route for it, only for create/delete attachment. But obviously, it’s possible, since it can be done with Trello UI.

Hello @eretick01

Just as the documentation says, Trello’s REST API doesn’t provide a PUT endpoint for editing an attachment’s URL or name.

Just because something can be done via the UI, doesn’t infer there is a corresponding REST API method, or vice-versa.

Thanks for your reply. I thought there is got to be a way to do it. Doesn’t Trello UI use API? Just curious.
The problem is adding/removing attachments leaves an unwanted marks in the card’s actions history. Can I do something with it?

Some Atlassain products have an internal ‘system’ API that the UI sends requests to. If you inspect the code on the various pages, you can sometimes see evidence of it. The underlying ability to make the attachment object appear on a window is done via the save-attachment capability, which is also available for PowerUps to use.

That capability just allows the name of the attachment to be edit, not the URL to it, so even that wouldn’t solve the problem you have.

There are many cases where the public REST API can’t always replicate the exact same functionality of the UI, and vice-versa. Unfortunately, Trello doesn’t have a formal feature request programme as Atlassian’s other products do, so you don’t know if others have already asked for a public facing REST API endpoint to alter attachments. It’s not a common topic.

You may as well just work with what you have and delete the attachment, then re-add it. Unless this is malicious activity you’re trying to hide, why worry about the action history?

PS. If my answer was correct, could you mark it as such. I’m greedy for the kudos :slight_smile:

1 Like

Hello @eretick01

I FOUND A SOLUTION! Well, to changing the name of the attached document or image via the REST API anyhow.

I did some poking around looking at Power Ups that change the name of the attachment on a card using the save-attachment capability, and they all call an undocumented REST API endpoint that is open to the public.

It seems you can do a PUT request to the /1/cards/{id}/attachments/{idAttachment} endpoint and change the value of the name property. IE:

PUT https://api.trello.com/1/cards/{id}/attachments/{idAttachment}

Request body:

{
    "key" : "{TrelloKey}",
    "token" : "{TrelloToken}",
    "name": "Attachment name changed!"
}

If you do try to change the url property for attached documents or images, you get a ‘Cannot change URL of uploads’ error message back, so we at least know that type of change to those types of attachments is not allowed.

The ability to do a PUT to that endpoint to update an attachment name isn’t on the REST API documentation page, so I’ll raise it as a bug, and see if it gets fixed.

1 Like

Thanks you! I appreciate your work. Yes, the error message Cannot change URL of uploads’ it’s right the message I’ve met. Unfortunately, my case is the changing the URL. I just… Can’t understand why it isn’t allowed. It feels like the same as changing the name, just a property of an object. Obviously, if someone tries to change the url of the attachment, he knows what he is doing. And since UI interface can do it, so it’s not a broke-everything-feature. That beats me.
Anyway, thanks for your additional researching, I believe someone will finds it helpful.

“And since UI interface can do it”

I can’t help but think you are mistaken. I’ve never seen any part of Trello’s native UI that allows an attachment’s URL to be edited, only the name can be edited, AFAIK:

Any change to the URL would immediately break the path to the object in the backend storage. It would require a re-index and re-generation of a new ID, which essentially makes it a whole new attachment, not to mention that all the thumbnails would need to be re-generated with new IDs on the same path. All of this would be essentially the same as deleting the attachment and adding a new one.

Can you please explain your use case of why you need to alter the attachment URL and what outcome you’re trying to achieve. Also, can you provide a screen grab of the UI where it allows the attachment’s URL to be edited.

Not exactly.
image
Don’t mind the url values, i just tested it, it was a Google Doc before, next another one google doc, and then some random url-format text. And every time it changed properly and didn’t made any marks in history. What’s why I thought it’s possible somehow.

A team moves their online documents from one source to onother, so now I need to replace more than 20k attachments links. I still can do it by recreating attachments (delete them and create them again with new url adresses), like you’ve said before, but I was hoping there is some more “clear” solution.
Nevermind.

Ahhh, now I understand. You’re not trying to alter an attached document / image’s properties but an attached link’s properties. The two are not the same.

Yes, you can do a PUT request to the /1/cards/{id}/attachments/{idAttachment} endpoint and change the values of both the name and url properties of an attached link. IE:

PUT https://api.trello.com/1/cards/{id}/attachments/{idAttachment}

Request body:

{
    "key" : "{TrelloKey}",
    "token" : "{TrelloToken}",
    "name": "Attachment name changed!",
    "url": "http://new_path_to_wherever"
}

I just tested and it works fine:

Ok! So It has a partial solution. Nice. It probably not works in most cases (since I don’t know yet how exactly they added docs, I just investigate a possibility for now).
Still, now I know a bit more thanks to you.

You can call me naive, but I still think it must be described in documentation =)

Hello again.
Just curious, can you specify what do you mean by

“This technique doesn’t work for attached Google Docs, as that uses some other mechanism to embed the object, and it can’t be edited at all, only deleted and re-added.”

I even tried to add an attachment using the button “Attachment” on the right card’s menu panel, chosed “Google Drive” and added a file from the popup Google Drive window.
And… Replacing the link using

PUT https://api.trello.com/1/cards/{id}/attachments/{idAttachment}

still works even for that document.

Also, can you tell where did you find that API route?
As I can see, it is not in the public API specification

I removed that reference, as it just adds confusion to the topic

I just used some initiative, did some testing and found that functionality. Yes, it’s not documented, but the Trello REST API documentation has never been perfect.

Yes, it’s not documented

Can we do something to influence on it? For example, ask a developers to add it to the documentation somehow?

I just used some initiative, did some testing and found that functionality.

Well, thanks a lot! You are amazing) You literally saved me.