# Add document (Rest API)

**URL:** <https://community.ofelia.com/t/add-document-rest-api/5538>\
**Category:** Q&A\
**Created:** [14 January 2015 15:35 UTC](https://community.ofelia.com/t/add-document-rest-api/5538 "2015-01-14T15:35:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarg](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jarg](https://community.ofelia.com/u/jarg)\
**Post date:** [14 January 2015 15:35 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/1 "2015-01-14T15:35:56Z")

</div>

Hello,

I’ m trying to upload files with bonita rest API and I had two problems:

1. To test rest Api, in chrome I make login in bonita portal, and created a case.  
In the same browser i open a new tab and in postman extension I build a request like this

url = [http://localhost:8080/bonita/API/bpm/caseDocument:](http://localhost:8080/bonita/API/bpm/caseDocument:)

data = {“caseId”:“29”,“file”:“C:\flexitex2.jpg”,“name”:“flexitex2”,“description”:“draft”}  
where my case id was = 29.

The server send back that response

{  
“id”: “3”,  
“creationDate”: “2015-01-14 14:42:16.237”,  
“author”: “25”,  
“index”: “-1”,  
“contentMimetype”: “”,  
“caseId”: “29”,  
“description”: “draft”,  
“name”: “flexitex2”,  
“fileName”: “”,  
“isInternal”: “true”,  
“submittedBy”: “25”,  
“url”: “documentDownload?fileName=null&contentStorageId=3”,  
“contentStorageId”: “3”,  
“version”: “1”  
}

The attr content type and fileName is empty.  
What I am doing wrong here?

1. In widget html in one form I have this script

$.post( “[http://localhost:8080/bonita/API/bpm/caseDocument](http://localhost:8080/bonita/API/bpm/caseDocument)”, JSON.stringify( {“caseId”: caseId, “file”: “C:\flexitex1.PNG”, “name”: “flexitex1”, “description”: “draft”}), });

this scripts runs when i click in one specific button.  
The server send back this response was:

exception: “class java.lang.NullPointerException”  
message: “”  
stacktrace: [“org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)”,…]  
0: “org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)”  
1: “org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:198)”  
2: “org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:188)”  
3: “org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:168)”  
4: “org.bonitasoft.web.rest.server.framework.APIServletCall.getJSonStreamAsItem(APIServletCall.java:129)”

What I am doing wrong in this script?

Can anyone help me with this call?

Thanks in advance and sorry for my english.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [19 January 2015 11:32 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/2 "2015-01-19T11:32:33Z")

</div>

Hello

In fact, the engine constructor allowed it in 6.4, but it was fixed in 6.4.2  
it is not allowed to create a case document with a content and no filename. because we are not able generate a correct filename to access it in the document download servlet.

I hope this information help you

Nicolas

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [19 January 2015 12:20 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/3 "2015-01-19T12:20:36Z")

</div>

I think it should be possible to achieve your use case by doing to separated call to the API:

- First call will create the process instance. See “Create a case” on this documentation page: [http://documentation.bonitasoft.com/bpm-api#case](http://documentation.bonitasoft.com/bpm-api#case)
- Second call will add the document to the process instance (document of the document will be stored by Bonita Engine). See “Add a document to a case” on this documentation page: [http://documentation.bonitasoft.com/bpm-api#casedocument](http://documentation.bonitasoft.com/bpm-api#casedocument). Note that file need to be located on the server. If file is on end user computer it needs first to be uploaded to the server. To upload the file to the server you can use [TenantUploadFileServlet](https://github.com/bonitasoft/bonita-web/blob/6.4.1/server/src/main/java/org/bonitasoft/console/common/server/servlet/TenantFileUploadServlet.java)

---

<div class="post-metadata">

**Author:** ![jarg](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jarg](https://community.ofelia.com/u/jarg)\
**Post date:** [19 January 2015 12:54 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/4 "2015-01-19T12:54:32Z")

</div>

Thanks for your answers,

I resolved the problem.  
My intention was develop in bonita form a user interface to upload multiple files. So, I created two types of interfaces (for test).  
In first interface it is possible to user attach one file for task, and interface show all filles of the process. I do this because, if we submitted a task with a file and the process return to this task again and user need to attach another file without override the first file, he can´t.  
In second interface the user can add multiple file to a task but for that, he have to put the full file path to upload the file in one textField.  
It works, but i have to do better, I am not satisfied for the second solution.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [19 January 2015 13:34 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/5 "2015-01-19T13:34:16Z")

</div>

Hello,

FYI, uploading multiple files within a single form can be achieved using the “Dynamic Web forms designer” feature that is part of the Subscription editions:  
[http://www.bonitasoft.com/how-we-do-it/compare-editions](http://www.bonitasoft.com/how-we-do-it/compare-editions)

Cheers,

---

<div class="post-metadata">

**Author:** ![stalinramirez](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@stalinramirez](https://community.ofelia.com/u/stalinramirez)\
**Post date:** [23 April 2015 03:35 UTC](https://community.ofelia.com/t/add-document-rest-api/5538/6 "2015-04-23T03:35:28Z")

</div>

Hola Jarg  
Estoy en un problema similar de adjuntar varios archivos podrias ayudarme??
