Submit

The submit call sends a piece of text to a predefined email address. This is primarily useful to submit anonymous contact forms.

Account configuration

Submission forms are often publicly available. For that reason, a special account should be set up for each form. The key may be all zeros, since it has to be published anyway. The account must contain a submit section with the destination parameters:

{"candy/contact-form": {"key": "0000000000000000000000000000000000000000000000000000000000000000", "submit": {"type": "email", "from": {"email": "website@example.com"}, "to": [{"email": "info@example.com"}], "reply to sender": true, "subject": "Inquiry {topic}", "text": "{text}"}}}

The following destination parameters can be specified:

type Must be "email". Other values are reserved for future use.
from The sender address.
to A list of recipient addresses.
cc A list of carbon copy addresses. (optional)
bcc A list of hidden carbon copy addresses. (optional)
reply to sender If set to true, the contact form sender address is used as reply-to address. (optional)
reply to A reply-to address, if reply to sender is not set. (optional)
subject The subject.
text The plain text version of the email body.
html The HTML version of the email body. (optional)

An address is written as follows:

{"name": "John Smith", "email": "john.smith@example.com"}

whereby the name is optional.

In the subject and body, {property} is replaced by the corresponding property value sent with the request.

If reply to is set to the special value "message", the reply-to address can be provided with the request.

HTTP/REST Requests

POST /backend/submit
Account: ACCOUNT ID
Timestamp: TIMESTAMP
Signature: SIGNATURE
{"topic": "...", "sender": {"name": "...", "email": ""}, "text": "..."}

Submits some text to a predefined destination. This is useful for contact forms which should be submitted to a predefined e-mail address. Create a separate account for each destination.

Response

  • 200
  • 400, if the request was invalid
  • 401, if the account ID or signature is missing or invalid
  • 403, if the account is not configured for submit calls
Account ID
Account key
JSON

JavaScript

Using Backend.js, a contact form (name, e-mail, message) can be submitted as follows:

const backend = new Backend('https://viereck.ch/backend');
const account = backend.account('your-account-id', '44705748... your-account-key');

sendButton.onclick = function(event) {
	const data = {
		sender: {
			name: name.value.trim(),
			email: email.value.trim()
			},
		name: name.value.trim(),
		email: email.value.trim(),
		message: message.value.trim()
		};

	account.submit(data, onDone, onError);

	function onDone(request) {
		successMessage.style.display = '';
		sendButton.style.display = 'none';
	}

	function onError(errorCode, request) {
		errorMessage.style.display = '';
	}
};