Zoho - Trademark
Blogs
ForumsSheet Home
 Writer HomeToll Free : 888 900 9646

<< API Home


Zoho Remote API



The Zoho Remote Application Programming Interface (API) lets any third-party application use the feature-rich editor of Zoho Writer for creating/editing documents. The API also allows such documents created to be pushed to one's own remote servers for saving (the documents aren't saved in Zoho Writer's servers).


A sample document opened using the Zoho Writer editor





 

Editing a Remote Document in Zoho Writer

Sample Code

Using multi-part form submit



To push the document from remote server (for making it load on the Zoho Writer editor), submit a multi-part form-data to Zoho Writer with the following fields

Field
Description
contentactual document content
filename
filename of the document with extension (supported formats : .doc, .rtf, .odt, .sxw, .html, .txt)
idunique id that will be submitted while saving the document (for reference)
formatthe format in which document should be saved on remote server (examples: doc, html, pdf, sxw, odt, rtf, txt )
persistence(optional)if this parameter is not passed or set to false, the document pushed to ZohoWriter will be editable only once. When the user exits the browser window, it will be automatically deleted
saveurl[REMOTE SERVER SAVE URL] - The Web URL should be a service that fetches the content of the updated document and saves it to the user specified location.

* document can be pushed from remote server to Zoho Writer in one format and can be saved in different format also


Sample multipart form


<form method="POST" action="http://export.writer.zoho.com/remotedoc.im?apikey=[apikey]&output=editor" enctype="multipart/form-data" target="_self">

File : <input type="file" name="content" size="38"> <br>

<input type="hidden" name="filename" value="mydocument.doc">

<input type="hidden" name="saveurl" value="[REMOTE SERVER SAVE URL]">

<input type="hidden" name="id" value="12345678">

<input type="hidden" name="format" value="doc">

<input type="submit" value="Edit" class="divbutton" name="submit">

</form>



* In order to edit a document in Zoho Writer, it must be submitted as multi-part form data either from the client side or it can be done as an emulated multi-part form submission on the server side of the remote server.


API URL


To access the multi-part form based remote API, the users should post to the following URL format mentioned below :

http://export.writer.zoho.com/remotedoc.im?apikey=[apikey]&output=editor


The output parameter decides the format in which output will be sent. By passing 'editor' as the output value the response will be javascript code snippet which automatically loads Zoho Writer editor with the document content opened for editing.

editor -- JavaScript code snippet that loads the Zoho Writer

url -- outputs a URL which contains encrypted Id for the document to be edited

by default the response will be a URL




Response Format for URL request:


URL=[url value1]

WARNING=[warning message]

RESULT=[TRUE/FALSE]


RESULTfield indicates the status of the action

Sample Response:


URL=http://export.writer.zoho.com/editor.im?doc=C77076EG003waI770c1
WARNING=
RESULT=TRUE



Using normal form submit


To push the document from the remote server, submit a form to Zoho Writer with the following form fields.

Field
Description
urlurl from which zoho writer can fetch the document.
Note
: it is mandatory to specify the absolute path of the document in url parameter with proper file extension.
filenamefilename of the document with extension
idunique id that will be submitted while saving the document (reference)
formatthe format in which document should be saved on remote server (examples: doc, html, pdf, sxw, odt, rtf, txt )
persistence(optional)if this parameter is not passed or set to false, the document pushed to ZohoWriter will be editable only once, when the user exits the browser window it will be automatically deleted
saveurl
[REMOTE SERVER SAVE URL] - The Web URL should be a service that fetches the content of the updated document and saves it to the user specified location.


Sample form


<form method="POST" action="http://export.writer.zoho.com/remotedoc.im
?apikey=[apikey]&output=editor" target="_self">

<input type="hidden" name="url" value="[REMOTE DOCUMENT URL]">

<input type="hidden" name="saveurl" value="[REMOTE SERVER SAVE URL]">

<input type="hidden" name="filename" value="mydocument.doc">

<input type="hidden" name="id" value="12345678">

<input type="hidden" name="format" value="pdf">

<input type="hidden" name="persistence" value="true">

<input type="submit" value="Edit" class="divbutton" name="submit">

</form>



* In order to edit a document in Zoho Writer, it must be submitted as form data either from the client side or it can be done as a emulated form submission on the server side of the remote server.

http://export.writer.zoho.com/remotedoc.im?output=editor

The output parameter decides the format in which output will be sent. By passing 'editor' as the output value the response will be javascript code snippet which automatically loads the Zoho Writer editor with the document content opened for editing.

editor -- JavaScript code snippet that loads the Zoho Writer

url -- outputs a URL which contains encrypted Id for the document to be edited

by default the response will be a URL


Response Format for URL request:


URL=[url value1]

WARNING=[warning message]

RESULT=[TRUE/FALSE]


RESULT field indicates the status of the action

Sample Response:


URL=http://export.writer.zoho.com/editor.im?doc=C77076EG003waI770c1
WARNING=
RESULT=TRUE



Saving the document in a remote server


The document which is edited in the Zoho Writer editor will be pushed to the remote server using multi-part form submission from the Zoho Writer Server. The URL to be used is specified at the time of pushing the document from remote server.

Field
Description
formatthe format in which the document should be saved on the remote server (examples: doc, html, pdf, sxw, odt, rtf, txt )
content
document content in desired format
filenamefilename of the document with extension
idunique id that was initally sent while pushing the document from remote server (reference)

* In order to process the saving of a document, the remote server should understand multi-part form submission with the above fields


Zoho API is an easy way to integrate Zoho Services into your application. Do have a go at the APIs by signing up for the key now. If you have any further questions regarding the Zoho API, write to us at api@zoho.com.


Note :
It is mandatory to have the remote server address set to "port number 80" for all the upload and download operations.


PHP Sample



When you wish to edit and save your document using Zoho Writer's editor to your remote server, you need to do a form submit from your application to Zoho Writer as mentioned here.

The response for this form will be a Zoho Writer editor with the content of the document loaded. After editing your document, when you press save, Zoho Writer converts the document to the required format(doc/pdf/sxw...etc.,) specified in the above form and sends the modified content to the saveurl.

Assume your saveurl is - http://yourwebsite.com/SaveDoc.do

This is how your SaveDoc.do in PHP will look like:

<?php

$tmp_filename = $_FILES['content']['tmp_name'];

$upload_status = move_uploaded_file($tmp_filename,"[Specify the absolute path where the document is to be stored along with the filename and file extension]");

?>


Below is the brief explanation of what the code does:

$_FILES['content']['tmp_name'] - The $_FILES array is where PHP stores all the information about files. There are two elements of this array which we need to understand:

content - content is the reference we assigned in our HTML form.

tmp_name - tmp_name contains the path to the temporary file that resides on the server.

move_uploaded_file - This function moves the temporary file to the location in your local server that you mention along with the file name and file extension. For example the remote server path could look like - /apache/htdocs/remotesave/test.doc.


ASP .NET Sample


This is how your SaveDoc.do in ASP.NET will look like:


'this is page load event

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'declaring variable - object declared to get the file upload content

 Dim m_objFile As HttpPostedFile
Dim filename As String

'here we get the request file name

m_objFile = Request.Files("content")

'here we are getting the exact file name what we send in the input html

filename = m_objFile.FileName().Substring(m_objFile.FileName().IndexOf("_") + 1)

'saving the path in the local server

Request.Files("content").SaveAs("C:\inetpub\" + filename)

End Sub
 


Please note that any text inside the code preceded by single quotes (') is a comment in ASP.Net.


Java Sample


Similarly a sample action written using Struts Application that will parse, retrieve and save the content sent from Writer to your local server will look like the one mentioned below :


import org.apache.struts.action.*;

import java.util.logging.Logger;
import java.util.logging.Level;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;

import java.util.Hashtable;
import java.io.*;

import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;

public class MySaveService extends Action {

public ActionForward execute (ActionMapping actionMap, ActionForm actionForm, HttpServletRequest httpReq, HttpServletResponse response) throws Exception {

OutputStream out=null;

response.setCharacterEncoding("UTF-8");

out=response.getOutputStream();

DiskFileUpload upload = new DiskFileUpload();

upload.setSizeMax(-1);

java.util.List list = upload.parseRequest(httpReq);

java.util.Iterator items = list.iterator();

String docName = null;

byte[] htmlStrInBytes = null;
String id = null;
String format = "doc";
String url=null;
String filename=null;

 
while (items.hasNext()) {
FileItem item = (FileItem) items.next();

if (item.getFieldName().equalsIgnoreCase("content"))
{
htmlStrInBytes = item.get(); //The modified content sent by the zohowriter service is saved in this variable htmlStrInBytes
}
 
if (item.getFieldName().equalsIgnoreCase("format"))
{
byte[] fmt = item.get();
format = new String(fmt);
}
 
if (item.getFieldName().equalsIgnoreCase("id"))
{
byte[] id1 = item.get();
id = new String(id1);
}
if (item.getFieldName().equalsIgnoreCase("filename"))
{
byte[] filename1 = item.get();
filename = new String(filename1);
}
}

int tmp=filename.indexOf(".");
if(tmp>=0)
{
filename=filename.substring(0,tmp)+"."+format;
}
String path ;//Specify the path where the document is to be stored
File f = new File(path);
 
FileOutputStream fos = new FileOutputStream(f);
if(f.exists())
{
fos.write(htmlStrInBytes);//Writing the content into the file
}
fos.close();
return null;
}

}