CMDBuild Forum

Upload attachment rest api v3

How can I upload an attachment with the new v3 Rest api?

This is well documented in the Web Service manual, specially page 19.

Thank you for your answer but I don’t understand what should I use in the request…

I have a card with id ${cardId} and a file on my server at the path ${attachmentfullpath}.

I want to upload on my cmdbuild.

My url is
url=${cmdbuild}/services/rest/v3/processes/${processId}/instances/${cardId}/attachments?scope=service

So I use curl in this way:

curl --include ${url} -H “Content-Type: application/json” -H “CMDBuild-Authorization: $sessionId” --data-binary “@${request}” -X POST

what should i write into the ${request} file?

{
“cardId”: ${cardId},
“attachment”: ${attachmentfullpath}.
“dataHandler”: ???
}

with

{
“cardId”: ${cardId},
“attachment”: ${attachmentfullpath}
}

I receive the following response:

{
“success”:false,
“messages”:
[

{
“level”:“ERROR”,
“show_user”:false,
“message”:“java.lang.NullPointerException”
}

]

}

I found the solution:

It works like the old versions.

curl -F attachment=@${request} -F filename=${filename} -F file=${fullpath} -H "CMDBuildAuthorization: ${sessionid}" ${url} -X POST

where request is

{
“category”:"${idCategoryDocument}",
“description”:"${filename}",
“file”:"${attachmentpath}"
}

1 Like