'use strict'; import React, {Component} from 'react'; import {withTranslation} from '../lib/i18n'; import {Trans} from 'react-i18next'; import {requiresAuthenticatedUser, Title, withPageHelpers} from '../lib/page' import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling'; import axios from '../lib/axios'; import {Button} from '../lib/bootstrap-components'; import {getUrl} from "../lib/urls"; import {withComponentMixins} from "../lib/decorator-helpers"; import styles from "./styles.scss" @withComponentMixins([ withTranslation, withErrorHandling, withPageHelpers, requiresAuthenticatedUser ]) export default class API extends Component { constructor(props) { super(props); this.state = { accessToken: null }; } @withAsyncErrorHandler async loadAccessToken() { const response = await axios.get(getUrl('rest/access-token')); this.setState({ accessToken: response.data }); } componentDidMount() { // noinspection JSIgnoredPromiseFromCall this.loadAccessToken(); } async resetAccessToken() { const response = await axios.post(getUrl('rest/access-token-reset')); this.setState({ accessToken: response.data }); } render() { const t = this.props.t; const accessToken = this.state.accessToken || 'ACCESS_TOKEN'; let accessTokenMsg; if (this.state.accessToken) { accessTokenMsg =
{t('personalAccessToken') + ': '}{accessToken}
; } else { accessTokenMsg =
{t('accessTokenNotYetGenerated')}
; } return (
{t('api')}
{accessTokenMsg}

{t('notesAboutTheApi')}

  • API response is a JSON structure with error and data properties. If the response error has a value set then the request failed.
  • You need to define proper Content-Type when making a request. You can either use application/x-www-form-urlencoded for normal form data or application/json for a JSON payload. Using multipart/form-data is not supported.

{t('Get subscribers')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}
    • start – {t('startPosition')} ({t('optionalDefault0')})
    • limit – {t('limitEmailsCountInResponse')} ({t('optionalDefault10000')})

{t('example')}

curl -XGET '{getUrl(`api/subscriptions/P5wKkz-e7?access_token=${accessToken}&limit=10&start=10&search=gmail`)}' 

{t('thisApiCallEitherInsertsANewSubscription')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('subscribersEmailAddress')} ({t('required')})
  • FIRST_NAME – {t('subscribersFirstName')}
  • LAST_NAME – {t('subscribersLastName')}
  • TIMEZONE – {t('subscribersTimezoneEgEuropeTallinnPstOr')}
  • MERGE_TAG_VALUE – {t('customFieldValueUseYesnoForOptionGroup')}

{t('additionalPostArguments')}:

  • FORCE_SUBSCRIBE – {t('setToYesIfYouWantToMakeSureTheEmailIs')} by default.
  • REQUIRE_CONFIRMATION – {t('setToYesIfYouWantToSendConfirmationEmail')}

{t('example')}

curl -XPOST '{getUrl(`api/subscribe/B16uVTdW?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com&MERGE_CHECKBOX=yes&REQUIRE_CONFIRMATION=yes'

{t('Response example')}:

"data": ("id":"TTrw41znK")

{t('thisApiCallMarksASubscriptionAs')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('subscribersEmailAddress')} ({t('required')})

{t('example')}

curl -XPOST '{getUrl(`api/unsubscribe/B16uVTdW?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com'

{t('Response example')}:

"data": ("id":"TTrw41znK", "unsubscribed":true)

{t('thisApiCallDeletesASubscription')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('subscribersEmailAddress')} ({t('required')})

{t('example')}

curl -XPOST '{getUrl(`api/delete/B16uVTdW?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com'

{t('Response example')}:

"data": ("id":"TTrw41znK", "deleted":true)

{t('thisApiCallCreatesANewCustomFieldForA')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • NAME – {t('fieldName')} ({t('required')})
  • TYPE – {t('oneOfTheFollowingTypes')}
    • text – Text
    • website – Website
    • longtext – Multi-line text
    • gpg – GPG Public Key
    • number – Number
    • radio – Radio Buttons
    • checkbox – Checkboxes
    • dropdown – Drop Down
    • date-us – Date (MM/DD/YYY)
    • date-eur – Date (DD/MM/YYYY)
    • birthday-us – Birthday (MM/DD)
    • birthday-eur – Birthday (DD/MM)
    • json – JSON value for custom rendering
    • option – Option
  • GROUP – {t('ifTheTypeIsOptionThenYouAlsoNeedTo')}
  • GROUP_TEMPLATE – {t('templateForTheGroupElementIfNotSetThen')}
  • VISIBLE – yes/no, {t('ifNotVisibleThenTheSubscriberCanNotView')}

{t('example')}

curl -XPOST '{getUrl(`api/field/B16uVTdW?access_token=${accessToken}`)}' \
--data 'NAME=Comment&TYPE=text'

{t('Response example')}:

"data": ("id":22, "tag":"MERGE_COMMENT")

{t('thisApiCallGetListOfBlacklistedEmails')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}
    • start – {t('startPosition')} ({t('optionalDefault0')})
    • limit – {t('limitEmailsCountInResponse')} ({t('optionalDefault10000')})
    • search – {t('filterByPartOfEmail')} ({t('optionalDefault')})

{t('example')}

curl -XGET '{getUrl(`api/blacklist/get?access_token=${accessToken}&limit=10&start=10&search=gmail`)}' 

{t('thisApiCallEitherAddEmailsToBlacklist')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('emailAddress')} ({t('required')})

{t('example')}

curl -XPOST '{getUrl(`api/blacklist/add?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com'

{t('thisApiCallEitherDeleteEmailsFrom')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('emailAddress')} ({t('required')})

{t('example')}

curl -XPOST '{getUrl(`api/blacklist/delete?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com'

{t('retrieveTheListsThatTheUserWithEmailHas')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

{t('example')}

curl -XGET '{getUrl(`api/lists/test@example.com?access_token=${accessToken}`)}'

{t('retrieveTheListsThatTheNamespaceHas')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

{t('example')}

curl -XGET '{getUrl(`api/lists-by-namespace/1?access_token=${accessToken}`)}'

{t('createListDescription')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • NAMESPACE – {t('namespace')} ({t('required')})
  • UNSUBSCRIPTION_MODE – {t('unsubscription')} ({t('required')}):
    • 0 - {t('onestepIeNoEmailWithConfirmationLink')}
    • 1 - {t('onestepWithUnsubscriptionFormIeNoEmail')}
    • 2 - {t('twostepIeAnEmailWithConfirmationLinkWill')}
    • 3 - {t('twostepWithUnsubscriptionFormIeAnEmail')}
    • 4 - {t('manualIeUnsubscriptionHasToBePerformedBy')}
  • NAME – {t('name')}
  • DESCRIPTION – {t('description')}
  • HOMEPAGE – {t('homepage')}
  • CONTACT_EMAIL – {t('contactEmail')}
  • DEFAULT_FORM – {t('webAndEmailFormsAndTemplatesUsedIn')}
  • FIELDWIZARD – {t('representationOfSubscribersName')}:
    • none - {t('emptyCustomNoFields')}
    • full_name - {t('nameOneField')}
    • first_last_name - {t('firstNameAndLastNameTwoFields')}
  • TO_NAME – {t('recipientsNameTemplate')}
  • LISTUNSUBSCRIBE_DISABLED – {t('doNotSendListUnsubscribeHeaders')}
  • PUBLIC_SUBSCRIBE – {t('allowPublicUsersToSubscribeThemselves')}
  • SEND_CONFIGURATION – {t('sendConfiguration-1')}

{t('example')}

curl -XPOST '{getUrl(`api/list?access_token=${accessToken}`)}' \
-d 'NAMESPACE=1' \
-d 'UNSUBSCRIPTION_MODE=0' \
-d 'NAME=list1' \
-d 'DESCRIPTION=a very nice list' \
-d 'CONTACT_EMAIL=test@example.com' \
-d 'HOMEPAGE=example.com' \
-d 'FIELDWIZARD=first_last_name' \
-d 'SEND_CONFIGURATION=1' \
-d 'PUBLIC_SUBSCRIBE=1' \
-d 'LISTUNSUBSCRIBE_DISABLED=0'

{t('Response example')}:

"data": ("id":"WSGjaP1fY")

{t('deleteListDescription')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

{t('example')}

curl -XDELETE '{getUrl(`api/list/WSGjaP1fY?access_token=${accessToken}`)}'

{t('Response example')}:

{t('Empty object')}

{t('forcesTheRssFeedCheckToImmediatelyCheck')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

{t('example')}

curl -XGET '{getUrl(`api/rss/fetch/5OOnZKrp0?access_token=${accessToken}`)}'

{t('sendSingleEmailByTemplateWithGiven')}

{t('Query params')}

  • access_token – {t('yourPersonalAccessToken')}

POST {t('arguments')}

  • EMAIL – {t('emailAddress')} ({t('required')})
  • SEND_CONFIGURATION_ID – {t('idOfConfigurationUsedToCreateMailer')}
  • SUBJECT – {t('subject')}
  • TAGS – {t('mapOfTemplatesubjectVariablesToReplace')}
  • ATTACHMENTS – {t('Attachments (format as consumed by nodemailer)')}

{t('example')}

curl -XPOST '{getUrl(`api/templates/1/send?access_token=${accessToken}`)}' \
--data 'EMAIL=test@example.com&SUBJECT=Test&TAGS[FOO]=bar&TAGS[TEST]=example'
); } }