Post

2 followers Follow
0
Avatar

Uploading a file to Clarizen via REST API

I've been trying to upload a json file from local storage to clarizen for easy retrieval as I'm working on an integration via api project for in-house development and require the storage and retrieval of a json file between local storage and clarizen storage on a near daily basis.

I first created a project with the hopes of attaching a file to it in the future. I have been able to upload manually via the interface and download via the api as well as get the upload url via api but whenever I try to make a POST to the url from the getUploadUrl response the response body is empty.

What is the correct parameter when POSTing? currently I'm sending a form-data of data:"file_path".

When looking at what gets sent in the request it seems to split the key:value of form data into name and filename so presumably the name of the key does not matter. Regardless of what I POST I get a 200 OK response with no response body. 


Whenever I try and make a POST to /upload with a json body including documentID,fileInformation(storage,filename), and uploadUrl I get an internal error.

Example:

{"documentId":"doc.id","fileInformation":{"storage":"Server","fileName":"file_name.txt"},"uploadUrl":"..."}

this results in an internal error.

Can someone please help in deciphering what the exact error message is and where I'm going wrong as well as exactly how to POST a file to the url retrieved after making a GET to /getUploadUrl..

I have looked over the relevant documentation and similar forum posts:

https://api.clarizen.com/V2.0/services/files/Upload

https://api.clarizen.com/V2.0/services/files/Download

https://api.clarizen.com/V2.0/services/files/getUploadUrl

https://success.clarizen.com/hc/en-us/community/posts/205579818-File-upload-and-attach-to-Request-via-REST-API

the internal error message referenceID is: 1rihUG0Ym5mxSXctQ1P647

Thanks!

Dribero Answered

Please sign in to leave a comment.

6 comments

0
Avatar

I have resolved this by manually creating a document under a project in the interface and then repeating steps inputting the document id instead of project ID in the json request body. I am trying to find the relevant references in the API on creating an entity, creating a document, and attaching the document to the entity. What is the endpoint/method for attachmentlink for the REST api? 

Thanks

Dribero 0 votes
Comment actions Permalink
1
Avatar

Hello there,

In the logs I can see that you're providing project ID instead of document ID:

{

   "documentId": "/Project/1cpa1lqd43i8spywssqif33u5228",

   "fileInformation": {

      "storage": "Server",

      "fileName": "Clarizen_Users.txt"

   },

   "uploadUrl": "https://api2.clarizen.com/v2.0/services/files/1446541-637078840987611866_ltt4ujihi0aKJQ5rEX2a3w-637078840987611866-A4234BC2075BA70C4C1B8D92E189EF973B1ADC9B/uploadFile"

}

As Eyal mentioned in his post, you need to create the document object and link it to the project and then upload the file in the document object you created:

I hope this helps.

Best regards,

Roland

Roland Pumputis 1 vote
Comment actions Permalink
0
Avatar

thanks for the reply Roland.

I realized that mistake and am happy to report that I can upload and download files without an issue now but am wondering how to create the link between a document and entity via the API.

I have created a task using /v2.0/services/data/createAndRetrieve (example: /Task/1cpa1lqd43i8spywssqif33u5227) and have also created a document using the same API method and received something like /Document/4fjcr9ugptiwqi7hpxby5o71d793.

How can I link the two of them so that when I navigate to the task I can see the file attached? I can not find an "AttachmentLink" related method or a method where I can specify a documentID and a parent entity ID.

Thanks!

Dribero 0 votes
Comment actions Permalink
0
Avatar

Hello there,

I think you should be able to create an AttachmentLink object by using the /v2.0/services/data/createAndRetrieve endpoint. Please make sure you specify Entity and Document in the JSON you send.

Best regards,

Roland

Roland Pumputis 0 votes
Comment actions Permalink
0
Avatar

I ran the /ListEntities endpoint and found the entity "AttachmentLink" so proceeded with your advice and crafted the request below and some variations of it.

I tried this:

{
"entity": {
"Id":"/AttachmentLink"
},
"fields": [
"Document":"/Document/34wk0120tk2wk6ukj4fjgk1of2345",
"Entity":"/Task/12kj3253jk2kj6hjg5hjmj1hy2634"]
}

all of my attempts resulted in an internal error. The latest one being: 5bXhOukscBSdj8roi51x

Where exactly should I be passing the document id and task id to create the attachment link? 

Thanks Roland!

Dribero 0 votes
Comment actions Permalink
1
Avatar

Hello there,

The correct format is as follows:

{
  "entity": {
    "Id":"/AttachmentLink",
    "Document":"/Document/34wk0120tk2wk6ukj4fjgk1of2345",
    "Entity":"/Task/12kj3253jk2kj6hjg5hjmj1hy2634"
  },
  "fields": [
    "ExternalId"
  ]
}

"fields" should be used to list fields that you would like to see in the response. "Document" and "Entity" should be listed in "entity".

I hope this helps.

Roland

Roland Pumputis 1 vote
Comment actions Permalink