Has anyone had success uploading document versions through the API? I find the documentation on the API challenging at best and desperately need some help...
Long story short, our company has religiously linked files into Workfront via Box. We've just found out that out IT dept is moving our cloud storage from Box to sharepoint in the next 6 weeks and I need to ensure we don't lose our linked files. The best/most elegant solution I can come up with is to store all files locally as a new version of the linked files. This way we won't lose any comments or proofs that are currently available directly in our projects.
My plan was to use fusion to listen for changes to projects over the next 6 weeks and, using the box connector, download the file and then re-upload. Unfortunately, fusion can only upload a file, not a new version unless I make a custom API call. This is where I got stuck. I did some googling and found a stack overflow conversation that suggests a post to this endpoint attask/api/v13.0/DOCV?updates={"handle":"DOCUMENT-HANDLE","documentID":"DOCUMENT-GUID","fileName":"FOO.png"}, but when I try it I get a 500 error. Also, I would need to determine how to obtain the "handle" for the documents, which it does not appear is available when getting details on the document via api, nor is it available in platform.
Any help would be greatly appreciated! WE have about 50K+ files that we need to move.
Thanks!
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi Jeff,
As you are getting a 500 error there seems to be something wrong with the URL of your API call.
First I would change the API version to 17.0.
Besides that uploading a document or a document version is a 2-step process, as also written in the Stack Overflow post you linked:
1. Call the endpoint upload to upload the file and get a handle
2. Call the endpoint docu to assign the document to a Workfront object (Project, Task, ...)
or in your case
2. Call the endpoint docv to assign an additional version to an existing document
Your call to docv seems to be correct, but you need a handle first. This is not persistent, so you cannot read it from the database. It is created in response to the upload call and will be removed after a while.
Regards
Lars
Views
Replies
Total Likes
Hi, I am having trouble with that first step of calling the upload endpoint and getting the handle back. I can't find the right notation or documentation about what I need to specify during the pass of my document to the url. I keep getting a 422 error back when I pass the following:
https://xxxxxxxxx.my.workfront.com/attask/api/v15.0/upload, along with my apiKey, a csv file, and content-type specification. Hoping I can get some help/advice on this, but let me know if you need any additional information to help me out. Appreciate any help! Thanks
using HttpClient client = new(socketsHandler, false);
AccessTokenResponse? token = await GetAccessToken();
if (token == null)
{
Debug.WriteLine("Token is null");
return;
}
client.DefaultRequestHeaders.Add("sessionID", token.AccessToken);
// Step 1: Upload the file to get a handle
using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read);
using var content = new MultipartFormDataContent();
using var fileContent = new StreamContent(fileStream);
content.Add(fileContent, "uploadedFile", fileName);
var uploadResponse = await client.PostAsync($"{ObjectFactory.WorkfrontBaseUrl}/attask/api/v17.0/upload", content);
var uploadResult = await uploadResponse.Content.ReadAsStringAsync();
// {"data":{"handle":"671...550","size":0,"name":"Test file for Upload to Workfront.docx","type":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","extension":"docx","uploaded":true}}
UploadResponse? upload = JsonSerializer.Deserialize<UploadResponse>(uploadResult);
// Step 2: Create the document in the project
DocumentContent documentContent = new()
{
Name = fileNoExtension, // "Test file for Upload to Workfront"
Handle = upload?.Data.Handle,
DocObjCode = "PROJ",
ObjID = projectID,
CurrentVersion = new()
{
Version = "v1.0",
FileName = fileName, // "Test file for Upload to Workfront.docx"
Ext = extension // "docx"
}
};
StringContent createDocContent = new(JsonSerializer.Serialize(documentContent), Encoding.UTF8, "application/json");
HttpResponseMessage createDocResponse = await client.PostAsync($"{ObjectFactory.WorkfrontBaseUrl}/attask/api/v17.0/document", createDocContent);
string createDocResult = await createDocResponse.Content.ReadAsStringAsync();
// {"data":{"ID":"671fad...680c9","name":"Test file for Upload to Workfront","objCode":"DOCU","description":null,"lastUpdateDate":"2024-10-28T15:27:39:266+0000"}}
Views
Replies
Total Likes
Views
Likes
Replies