Discussion Forums

Creating File Activities

 
Apprentice
8 posts

Hello; I am able to create a Note activity successfully but File activities are more proving elusive…

This works:

parameters = {‘parent’:892394, ‘data’:{‘details’:‘hello solve360’}}
connection.request(“POST”, “/companies/note”, json.dumps(parameters), headers)

This fails:

parameters = {‘parent’:892394, ‘data’:{‘caption’:‘license.txt’,‘file’:‘the files content’}}
connection.request(“POST”, “/companies/file”, json.dumps(parameters), headers)

Avatar
Administrator
1823 posts

Perhaps we need to be clarify this point in the API documentation.  Our file upload method supports only form-urlencoded POSTS i.e. currently JSON and XML cannot be used to upload files.  While it’s probably technically possible to support the other formats they are not commonly used to transfer files.

Apprentice
8 posts

Do you have an example of a working post?  Its not clear how the “data” part of the post should be encoded…  Its currently giving me a “200 OK” with “Wrong file field” as the content…

Avatar
Administrator
1823 posts

A form sample would look something like this:

<form enctype="multipart/form-data" method="post" action="https://secure.solve360.come/companies/file/">
  <
input type="text" name="parent"/>
  <
input type="file" name="file"/>
  <
input type="submit" value="OK"/>
</
form

Which will post form-encoded data to the service as:

parent  {parentID}
file    filename
="{fileName}" Content-Type{fileMimeType} 

Or more verbosely something similar to:

POST /companies/fileHTTP/1.1
Host
secure.solve360.com
Accept
text/xml
Authorization
Basic {credentials}
Content
-Typemultipart/form-databoundary=---------------------------32972041628286
Content
-Length311

-----------------------------32972041628286
Content
-Dispositionform-dataname="parent"

{parentId}
-----------------------------32972041628286
Content
-Dispositionform-dataname="file"filename="{fileName}"
Content-Type{fileMimeType}

{encodedFileContent}
-----------------------------32972041628286--
Connectionclose 

Avatar
Administrator
1823 posts

Example to upload a file from the command line using cURL:

curl -'{userEmail}:{userApiToken}' --"parent=106829" -"file=@./test.txt;type=text/html" https://secure.solve360.com/contacts/file/