'use strict'; import React, { Component } from 'react'; import { translate, Trans } from 'react-i18next'; import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page' import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling'; import URL from 'url-parse'; import axios from '../lib/axios'; import { Button } from '../lib/bootstrap-components'; @translate() @withPageHelpers @withErrorHandling @requiresAuthenticatedUser export default class API extends Component { constructor(props) { super(props); this.state = { accessToken: null }; } @withAsyncErrorHandler async loadAccessToken() { const response = await axios.get('/rest/access-token'); this.setState({ accessToken: response.data }); } componentDidMount() { this.loadAccessToken(); } async resetAccessToken() { const response = await axios.post('/rest/access-token-reset'); this.setState({ accessToken: response.data }); } render() { const t = this.props.t; const thisUrl = new URL(); const serviceUrl = thisUrl.origin + '/'; const accessToken = this.state.accessToken || 'ACCESS_TOKEN'; let accessTokenMsg; if (this.state.accessToken) { accessTokenMsg =
{t('Personal access token') + ': '}{accessToken}
; } else { accessTokenMsg =
{t('Access token not yet generated')}
; } return (
{t('API')}
{accessTokenMsg}

{t('Notes about the API')}

POST /api/subscribe/:listId – {t('Add subscription')}

{t('This API call either inserts a new subscription or updates existing. Fields not included are left as is, so if you update only LAST_NAME value, then FIRST_NAME is kept untouched for an existing subscription.')}

GET {t('arguments')}

POST {t('arguments')}

{t('Additional POST arguments')}:

{t('Example')}

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

POST /api/unsubscribe/:listId – {t('Remove subscription')}

{t('This API call marks a subscription as unsubscribed')}

GET {t('arguments')}

POST {t('arguments')}

{t('Example')}

curl -XPOST {serviceUrl}api/unsubscribe/B16uVTdW?access_token={accessToken} \
--data 'EMAIL=test@example.com'

POST /api/delete/:listId – {t('Delete subscription')}

{t('This API call deletes a subscription')}

GET {t('arguments')}

POST {t('arguments')}

{t('Example')}

curl -XPOST {serviceUrl}api/delete/B16uVTdW?access_token={accessToken} \
--data 'EMAIL=test@example.com'

POST /api/field/:listId – {t('Add new custom field')}

{t('This API call creates a new custom field for a list.')}

GET {t('arguments')}

POST {t('arguments')}

{t('Example')}

curl -XPOST {serviceUrl}api/field/B16uVTdW?access_token={accessToken} \
--data 'NAME=Birthday&TYPE=birthday-us&VISIBLE=yes'

GET /api/blacklist/get – {t('Get list of blacklisted emails')}

{t('This API call get list of blacklisted emails.')}

GET {t('arguments')}

{t('Example')}

curl -XGET '{serviceUrl}api/blacklist/get?access_token={accessToken}&limit=10&start=10&search=gmail' 

POST /api/blacklist/add – {t('Add email to blacklist')}

{t('This API call either add emails to blacklist')}

GET {t('arguments')}

POST {t('arguments')}

{t('Example')}

curl -XPOST '{serviceUrl}api/blacklist/add?access_token={accessToken}' \
--data 'EMAIL=test@example.com&'

POST /api/blacklist/delete – {t('Delete email from blacklist')}

{t('This API call either delete emails from blacklist')}

GET {t('arguments')}

POST {t('arguments')}

{t('Example')}

curl -XPOST '{serviceUrl}api/blacklist/delete?access_token={accessToken}' \
--data 'EMAIL=test@example.com&'

GET /api/lists/:email – {t('Get the lists a user has subscribed to')}

{t('Retrieve the lists that the user with :email has subscribed to.')}

GET {t('arguments')}

{t('Example')}

curl -XGET '{{serviceUrl}}api/lists/test@example.com?access_token={{accessToken}} 
); } }