Hello.
I'm doing an Web services to send a document to sign, the api request the Url of the document so I'm using the following link https:[creatio instance]/0/rest/FileService/GetFile/70ec5d9f-a55e-4f5c-8f59-30d2c5149c4a/ef68e95e-ef77-eddf-dfa8-685557ee4875
70ec5d9f-a55e-4f5c-8f59-30d2c5149c4a correspons to the UId from the SysSchema table where the attachments are stored and the ef68e95e-ef77-eddf-dfa8-685557ee4875 is the Id of the attachment. This URL allows me to dowloand the document to my computer, so I know that is the right link but when I used it in the web service it says that there is no document.
The json of the request is the following
{ "url_doc": { "url": "https://151929-crm-bundle.creatio.com/0/rest/FileService/GetFile/70ec5d9f-a55e-4f5c-8f59-30d2c5149c4a/ef68e95e-ef77-eddf-dfa8-685557ee4875", "name": "Contrato.pdf" }, "stickers": [ { "authority": "Vinculada a Correo Electronico por Liga", "stickerType": "line", "dataType": "email", "email":"laura@artica.digital", "data": "laura@artica.digital", "imageType": "stroke", "page": 0, "rect": { "lx":74.88173, "ly":312.32596, "tx":196.9875, "ty":373.37885 } } ] }
When I sent the request the response is
{ "error": "No document" }
I had try this request with a Dropbox URL and works fine but I need to send the documents that are generated by the Word Reports. That why I'm trying to get the document from Creatio using the URL the API also gives me the option of sending the document using base64 but I dont know how to convert the file easly.
Can you help me please to know what is happenig?
Thank you
Like
The reason why this isn't working is because FileService/GetFile requires authentication to read. This is not an anonymous endpoint. The receiver of this, where ever you're sending this URL of the document to, is actually getting a 401 Unauthorized.
You'd have to either go the route of sending the base64 of the file, or expose an anonymous service in Creatio to provide the file to the other service.
Ryan
Ryan Farley,
Thank you, can you explain me please how can I convert the file to base64 please, I had see some examples but I not sure if I can do it using a script task in a business process or a source code
Laura Jurado,
The code would look something like this (not tested, but this should get you started). For this, I have two process params, one a uniqueidentifier AccountFileId (an Id of an account file) and second an unlimited text AccountFileBase64. The script task would look something like this:
var fileId = Get<Guid>("AccountFileId"); var entity = UserConnection.EntitySchemaManager.GetInstanceByName("AccountFile").CreateEntity(UserConnection); if (entity.FetchFromDB(fileId)) { var base64FileData = Convert.ToBase64String(entity.GetBytesValue("Data")); Set("AccountFileBase64", base64FileData); }
Ryan