-
Notifications
You must be signed in to change notification settings - Fork 110
API & Developer Manual
% PEPS API Guide % MLstate
This document is a preliminary version of the PEPS public API.
PEPS offers numerous APIs, and is gaining APIs quickly. This document details the endpoints and their detailed use. A sample python script demonstrates the practical use of the PEPS API.
To start an OAuth connection with a pair of consumer key and secret, it suffices to declare them in the configuration file config.py:
# OAuth
consumer_key = '123'
consumer_secret = '456'The command webmail = WebmailApi() will initiate the connection using these parameters.
To switch to direct login, the consumer_key must be assigned to the empty string in config.py.
The credentials are prompted during the construction of the WebmailApi object.
def message_list(self, maxResults=None, pageToken=None, labelId='INBOX')Fetch a list of user messages.
-
labelIdspecifies the source box. -
maxResultslimits the number of results (defaults to50). -
pageToken: by default, only the most recent messages are fetched. ThepageTokenallows to skip a number of messages (it is typically a message identifier). If successful, the response will be a json value of the form:
{
'messages': [{'id': string}],
'nextPageToken': string,
'resultSizeEstimate': integer
}def message_modify(self, id, change)Modify the flags of a single message.
-
idspecifies the message. -
changechanges to apply to the message. The changes must be of the following form, wherein the label ids correspond to folder identifiers.
{
'addLabelIds': [string],
'removeLabelIds': [string]
}If successful, the response will be a json value of type
{
'id': string,
'labelIds': [string]
}def message_attachment(self, id, attachmentId)Return a specific message attachment.
-
idspecifies the message. -
attachmentIdattachment's identifier. If successful, the response will be a json value of the form:
{
'data': bytes,
'size': integer,
'attachmentId': string
}The attachment metadata is returned in the message multipart (message_get endpoint), including the fields
{
'filename': string,
'mimeType': string
}For more transparency, the type tags has been defined which include both folders and labels. Tag methods have been grouped together in the API path `/users/me/tags.. following the same pattern as folder methods, with notable differences:
def tag_get(self, id, attachmentId)Return a specific tag.
-
idspecifies the message.
If successful, the response will be a json value of type:
{ 'label': {'id': integer, 'name': string, 'category': category} }if the tag corresponds to a label, and
{
'folder':
{
'id': string,
'name': string,
'content':
{
'count': integer,
'starred': integer,
'unread': integer,
'new': integer
}
}
}otherwise. Label categories should be {'personal': {}} or {'shared': {}}.
def tag_get(self)List personal labels and folders. The response will be a json value with two fields:
{
'folders': [folder],
'labels': [label]
}The types folder and label match those used in tag_get.
def tag_create(self, data)def tag_update(self, id, data)Create or update a tag. The data parameters used are identical for both methods.
-
ididentifier of the tag to be modified -
dataupdate parameters
In case the update is successful, the id of the tag is returned as {id: string} in the response body.
The data parameters must be of the form:
{
'label':
{
'name': string,
'description': string,
'category': category
}
}for labels, and
{ 'folder': {'name': string} }for folders.
def file_get(self, path)Fetch the contents of a resource (file or directory).
-
paththe path identifying the resource If successful, the response will include the file contents (or the empty string if a directory), as well as the resource metadata in theX-Webmail-Metadataheader:
{
'id': string,
'hash': bytes, // Not implemented yet.
'name': string,
'path': string,
'is_dir': boolean,
'modified': integer, // Date of the last modification.
'icon': string,
// File only.
'rev': string,
'thumb_exists': boolean,
'mime_type': string,
'size': integer, // Human readable.
'bytes': integer,
'class': string, // New in webmail; file security class.
// Directory only.
'contents': [..] // List the elements inside a directory (metadata)
}Reasons for failure can be:
- File not found, which causes a
404error - Unauthorised
401(user does not have access to this resource)
def file_metadata(self, path, list=False, file_limit=10000)Fetch a resource metadata.
-
pathpath to the resource -
listlist folder contents -
file_limitnot used
The metadata is returned in the response body.
PEPS uses end-to-end encryption. Therefore, API clients should implement encryption on their own. Since implementing cryptography is hard, we recommend that you contact MLstate to get in touch with us to learn more about encryption APIs and how to use them.
GET "/oauth/request_token" .*
GET "/oauth/authorize" .*
POST "/oauth/access_token" .*
GET "/oauth/gnameadmin" .*
GET "/oauth/logout" .*
POST "/login" .*
Create: POST "/users/" uid=user_id "/drafts"(.)
Delete: DELETE "/users/" uid=user_id "/drafts/" mid=message_id
Get: GET "/users/" uid=user_id "/drafts/" mid=message_id
List: GET "/users/" uid=user_id "/drafts": Http.Json.not_found({error
Update: PUT "/users/" uid=user_id "/drafts/" mid=message_id
Send: POST "/users/" uid=user_id "/drafts/send"
List: GET "/users/" uid=user_id "/history" ("?" .*)?
Create: POST "/users/" uid=user_id "/folders" ("?" .*)?
Delete: DELETE "/users/" uid=user_id "/folders/" fid=folder_id ("?" .*)?
List: GET "/users/" uid=user_id "/folders" ("?" .*)?
Update: PUT "/users/" uid=user_id "/folders/" fid=folder_id ("?" .*)?
Get: GET "/users/" uid=user_id "/folders/" fid=folder_id ("?" .*)?
Patch: PATCH "/users/" uid=user_id "/folders/" fid=folder_id ("?" .*)?
Get: GET "/users/" uid=user_id "/tags/" id=string_id ("?" .*)?
List: GET "/users/" uid=user_id "/tags" ("?" .*)?
Delete: DELETE "/users/" uid=user_id "/tags/" id=string_id ("?" .*)?
Create: POST "/users/" uid=user_id "/tags" ("?" .*)?
Update: PUT "/users/" uid=user_id "/tags/" id=string_id ("?" .*)?
Delete: DELETE "/users/" uid=user_id "/messages/" mid=message_id ("?" .*)?
Get: GET "/users/" uid=user_id "/messages/" mid=message_id ("?" .*)?
List: GET "/users/" uid=user_id "/messages" ("?" .*)?
Modify: POST "/users/" uid=user_id "/messages/" mid=message_id "/modify" ("?" .*)?
Send: POST "/users/" uid=user_id "/messages/send" ("?" .*)?
Trash: POST "/users/" uid=user_id "/messages/" mid=message_id "/trash" ("?" .*)?
Untrash: POST "/users/" uid=user_id "/messages/" mid=message_id "/untrash" ("?" .*)?
GET "/users/" uid=user_id "/messages/" mid=message_id "/attachments/" fid=file_id ("?" .*)?
History: GET "/users/history" ("?" .*)?
Get: GET "/users/" uid=user_id ("?" .*)?
Create new users: POST "/users" ("?" .*)?
Update existing users (except for teams): PUT "/users/" uid=user_id ("?" .*)?
List: GET "/users" ("?" .*)?
Delete: DELETE "/users/" uid=user_id ("?" .*)?
Update user teams: PUT "/users/" uid=user_id "/move" ("?" .*)?
History: GET "/teams/history" ("?" .*)?
Get: GET "/teams/" tid=team_id ("?" .*)?
Create: POST "/teams" ("?" .*)?
Update: PUT "/teams/" tid=team_id ("?" .*)?
Delete: DELETE "/teams/" tid=team_id ("?" .*)?
List: GET "/teams" ("?" .*)?
Metadata: GET "/files/metadata/" path=((!"?" .)*) ("?" .*)?
Folder creation: POST "/fileops/create_folder" ("?" .*)?
File and directory copy: POST "/fileops/copy" ("?" .*)?
Deletion: POST "/fileops/delete" ("?" .*)?
Move: POST "/fileops/move" ("?" .*)?
GET "/notify/" user=user_id ("?" .*)?