EmailsApiV2Controller

Extends \HttpApiV2Controller

Class EmailsApiV2Controller

This controller provides a gateway to the EmailService of the system. The user is able to get, send, queue and delete email records through his shop. Email forwarding is not directly supported but can be easily implemented by getting an existing email and then sending it with the updated contact addresses.

API consumers can also upload attachments through the AttachmentsApiV2Controller and later use them within their emails. The upload operation must be executed before sending/queuing the email because it is not possible to send the email JSON data and upload a file at the same time. For more info see the AttachmentsV2Controller.

category

System

package

ApiV2Controllers

Methods

AbstractApiV2Controller Constructor

__construct(\Slim\Slim $api, array $uri) 
inherited

Call this constructor from every child controller class in order to set the Slim instance and the request routes arguments to the class.

deprecated

The "__initialize" method will is deprecated and will be removed in a future version. Please use the new "init" for bootstrapping your child API controllers.

Throws
\HttpApiV2Exception

Through _validateRequest

Arguments

$api

\Slim\Slim

Slim framework instance, used for request/response manipulation.

$uri

array

This array contains all the segments of the current request, starting from the resource.

delete

delete() 
api
todo

Do not throw an error if a record does not exist. Because this is what other controllers do.

apiVersion

2.1.0

apiName

DeleteEmail

apiGroup

Emails

apiDescription

Delete an email record from database. To see an example usage take a look at docs/REST/samples/email-service/remove_email.php.

apiSuccess

Response-Body If successful this method returns information about the deleted record.

apiExample

{curl} Delete Email with ID = 572 curl -X DELETE --user admin@shop.de:12345 http://shop.de/api.php/v2/emails/572

apiSuccessExample

{json} Success-Response { "code": 200, "status": "success", "action": "delete", "emailId": 73 }

apiError

400-BadRequest The email ID parameter is missing or is not valid.

get

get() 
api
apiVersion

2.1.0

apiName

GetEmails

apiGroup

Emails

apiDescription

Get multiple or a single email record through the GET method. This resource supports the following GET parameters as described in the first section of documentation: sorting minimization, search, pagination. Additionally you can filter emails by providing the GET parameter "state=pending" or "state=sent". These filter parameters do not apply when a single emails record is selected (e.g. api.php/v2/emails/84) or when the emails are searched by the "q" parameter. To see an example usage take a look at docs/REST/samples/email-service/fetch_email.php

apiExample

{curl} Get All Emails curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/emails

{curl} Get Email With ID = 527 curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/emails/527

{curl} Get Pending Emails curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/emails?state=pending

{curl} Search Emails curl -i --user admin@shop.de:12345 http://shop.de/api.php/v2/emails?q=admin@shop.de

apiError

404-NotFound Email record not found.

apiErrorExample

Error-Response HTTP/1.1 404 Not Found { "code": 404, "status": "error", "message": "Email record could not be found." }

getCallableResource

getCallableResource( $controller, array $mappedURI, \Slim\Slim $api) 
inherited static

Arguments

$controller

$mappedURI

array

$api

\Slim\Slim

post

post() 
api
apiVersion

2.1.0

apiName

SendEmail

apiGroup

Emails

apiDescription

This method will send and save a new or an existing email to the system. If you include mail attachments then they must already exist in the server. You will need to provide the full path to the file. To see an example usage take a look at docs/REST/samples/email-service/send_email.php

apiParamExample

{json} Request-Body { "subject": "Test Subject", "sender": { "emailAddress": "sender@email.de", "contactName": "John Doe" }, "recipient": { "emailAddress": "recipient@email.de", "contactName": "Jane Doe" }, "replyTo": { "emailAddress": "reply_to@email.de", "contactName": "John Doe (Reply To)" }, "contentHtml": "HTML Content", "contentPlain": "Plain Content", "bcc": [ { "emailAddress": "bcc@email.de", "contactName": "Chris Doe" } ], "cc": [ { "emailAddress": "cc@email.de", "contactName": "Chloe Doe" } ], "attachments": [ { "path": "/var/www/html/shop/uploads/attachments/1434614398/myfile.txt", "name": "Display For MyFile.txt" } ] }

apiParam

{Number} [id] If provided then an existing email will be resend (only applies to URL).

{String} [subject] Email subject to be sent.

{Object} sender Contains the sender contact data.

{String} sender.emailAddress Sender's email address.

{String} [sender.contactName] Sender display name.

{Object} recipient Contains the recipient contact data.

{String} recipient.emailAddress Recipient's email address.

{String} [recipient.contactName] Recipient's display name.

{Object} replyTo Contains the reply to contact data.

{String} replyTo.emailAddress Email address of the 'Reply-To' contact.

{String} replyTo.contactName Name of the 'Reply-To' contact.

{String} [contentHtml] Email plain content.

{String} [contentPlain] Email HTML content.

{Array} [bcc] Contains the BCC contacts of the email.

{Array} [cc] Contains the CC contacts of the email.

{Array} [attachments] Contains the attachment data.

{String} attachments[].path The path to the attachments (the file must already exist in the server).

{String} [attachments[].name] Set a display name for the attachment file (must also contain the file extension).

apiSuccess

(Success 201) Response-Body If successful, this method returns a complete email resource in the response body.

apiError

400-BadRequest Email data were not provided.

404-NotFound Email record was not found.

apiErrorExample

Error-Response (400) HTTP/1.1 400 Bad Request { "code": 400, "status": "error", "message": "Email data were not provided." }

Error-Response (404) HTTP/1.1 404 Not Found { "code": 404, "status": "error", "message": "Email record was not found." }

put

put() 
api
apiVersion

2.1.0

apiName

QueueEmail

apiGroup

Emails

apiDescription

This method will queue a new email so that it can be send later (with the POST method). See the "post" method for parameter description. To see an example usage take a look at docs/REST/samples/email-service/queue_email.php

apiSuccess

(Success 200 - Email Was Queued) {String} Response-Body If successful, this method returns a complete email resource in the response body.

apiError

400-BadRequest Email data were not provided.

apiErrorExample

Error-Response HTTP/1.1 400 Bad Request { "code": 400, "status": "error", "message": "Email data were not provided." }

Constants

Defines the default page offset for responses that return multiple items.

DEFAULT_PAGE_ITEMS
inherited
var

Default controller to be loaded when no resource was selected.

DEFAULT_CONTROLLER_NAME
inherited
var

Defines the maximum request limit for an authorized client.

DEFAULT_RATE_LIMIT
inherited
var

Defines the duration of an API session in minutes.

DEFAULT_RATE_RESET_PERIOD
inherited
var

Properties