r/TOPdesk • • Feb 04 '26

Upload document to Asset by API

Hi,

Does anyone know if it is possible to upload a retrieved file (eg. a .pdf file from a change) directly to a specific asset, namely the connected Object on that change?
I have an action sequence to retrieve the file from the change, but I cannot seem to upload it to de Asset.
After the file is retrieved by the previous step with URL: ${_responses.get_change_progresstrail.body.results?last.downloadUrl?no_esc} , I have these steps:

Step upload POST:

  • URL: /tas/api/assetmgmt/assets/${_responses.get_change.body.asset.id}/uploads
  • Content-Type: multipart/form-data; boundary=BOUNDARY
  • Contents:

--BOUNDARY
Content-Disposition: form-data; name="file"; filename="${_responses.get_change_progresstrail.body.results?last.fileName}"
Content-Type: application/plain;charset=utf-8
Content-Transfer-Encoding: base64

${_base64(_responses.donwnload_attachment.rawBody)}
--BOUNDARY--

As a result I get 404 not found and I think that has to do with my endpoint, as the document itself is processed:

2026-02-04T12:43:47.457002153Z] Request: POST /tas/api/assetmgmt/assets/ad768364-2e81-43d0-8ad1-ba84a392ba4f/uploads
Request headers: {Authorization=[[omitted from the logs]], XTopdeskInternalUrl=[Automatically set due to using a relative URL], XTopdeskTenant=[Automatically set due to using a relative URL], Content-Type=[multipart/form-data; boundary=BOUNDARY]}
Request body: --BOUNDARY
Content-Disposition: form-data; name="file"; filename="Test.pdf"
Content-Type: application/plain;charset=utf-8
Content-Transfer-Encoding: base64

JVBERi0xLjUKJeLjz9MKNCAwIG9iago8PC9Db2xvclNwYWNlL0RldmljZVJHQi9NYXNrIFsyMTMgMjEzIDI4IDI4IDIyNyAyMjcgXS9TdWJ0eXBlL0l etc… etc… etc… etc… 
--BOUNDARY--
[2026-02-04T12:43:47.459492605Z] Response status: 404 Not Found
Response headers: [Access-Control-Allow-Origin=*,Cache-Control=no-store,Connection=keep-alive,Content-Length=0,Date=Wed, 04 Feb 2026 12:43:47 GMT,Server=openresty,X-Content-Type-Options=nosniff,X-Robots-Tag=noindex,nofollow,X-XSS-Protection=1; mode=block]
Response body: 
[2026-02-04T12:43:47.459494713Z] Request was unsuccessful
[2026-02-04T12:43:47.459497769Z] Storing response data

The asset has the document widget active, so it's not that. But what is it ?

2 Upvotes

10 comments sorted by

2

u/bw_van_manen Feb 04 '26

I think you have the wrong syntax for your boundary. First you define the boundary as BOUNDARY, but then you use --BOUNDARY-- and --BOUNDARY.

You should pick one and use that exact same text in all 3 places.

Also, I'd recommend picking something a little more unique than just 'BOUNDARY'. If someone uses the word boundary somewhere in the file name or content it would mess up the entire API call.

1

u/OutintheBlue Feb 04 '26

Thanks for your reply.
To be honest, I don't have really any clou what this BOUNDARY part does technically. I figured it just really downloads the file. I just copied this part from an excisting actionsequence in MyTOPdesk (KI 13680 - https://my.topdesk.com/tas/public/ssp/content/detail/knowledgeitem?unid=dc04d7dd0e03475da9056ff52ee347b4)
And in there is the same set up with both  --BOUNDARY-- and --BOUNDARY

But I changed it now all to BOUNDARY as you said (so 3 times the same) but still the same result.

2

u/ThunderStruck1984 Feb 04 '26

According to the docs the seems to be tas/api/assetmgmt/uploads?assetId=[assetid]

See: https://developers.topdesk.com/explorer/?page=assets#/Uploads/upload

2

u/ThunderStruck1984 Feb 04 '26

Btw, what helps for me is trying it out in postman and once that succeeds copy the code from that app and adjust to what needs to be done in the actionsequence.

1

u/OutintheBlue Feb 04 '26

Whow. Thanks a lot, That did the trick. I've been on that page, but I still haven't really figured out how to interpret the given information on there. Let alone work with Postmen, as I am not an IT technican.

3

u/OutintheBlue Feb 04 '26

Cheered too soon, as I did get a 200 OK response now, however, the file didn't attach to the asset.
But in the meantime I've been looking into it more and built a new action sequence based on the the info stated on KI 15593 in MyTopdesk which refers to KI 17686, but then for assets.
And that works! The file is now attached to the asset, now that I have the correct URL, thanks t o you. Thanks!

1

u/FreakOutITGeek Mar 18 '26

I’m trying to do something similar ( getting a PDF document from an incident and trying to upload it to an asset). The asset upload isn’t working for me, no matter which KI details (thanks for the pointers) I follow.

I would be interested in understanding how you got this working. Any chance of providing further details?

Thanks

3

u/ThunderStruck1984 Feb 04 '26

No problem..

In general a 404 means that page doesn’t exist, so even if the code is right the url will never work. Try to get that error gone first into a 400 bad request (right page, wrong code). A 405 means right page, wrong method (doing a post when a patch/put is expected or vice versa per example)