WPNewsman

Use WPNewsman API

All requests must be addressed to the script api.php

The script has two required parameters: method and key.

By default all methods respond with appropriate HTTP codes on errors. Sometimes an environment doesn’t allow to properly handle error responses, so you can add a bepositive=1 parameter to your request and the plugin will always respond with the “200 Ok” HTTP code. In this case only the “state: false” property of the response JSON object will indicate an error.

Available methods:

  • addEmail adds the subscriber and sets the “Confirmed” status for him. The additional required parameter is email. Other parameters will be added to the JSON object in the database.
  • getLists returns the subscribers’ lists
  • getListFieldsThis method returns all the available fields for the list.
  • downloadList returns the CSV or JSON file with subscribers. The additional required parameter is listId. The additional parameter links can contain the list of links that must be generated for each subscriber. Possible types of links are confirmation-link, resend-confirmation-link and unsubscribe-link. Other two parameters of this method are offset and limit. offset allows skip xx subscribers and return the subscribers starting from the xx number. limit allows limit the number of subscribers to return.
  • unsubscribe unsubscribes reciepients from the list

See the requests and responses below.

Method: addEmail

Params:

listIdrequired List id
full-cycleoptional, 0 or 1, default 0. Use full-cycle subscription (sends confirmation required email) as if subscriber submitted the subscription form.
use-excerptsoptional, 0 or 1, default 0, can be used only with full-cycle. Instead of providing a link to the action page outputs the page excerpt.

Request:

api.php?method=addEmail&key=API_KEY&listId=2&first-name=John&last-name=Doe&email=john@doe.com

Response:

normal
no record in the DB
{
state: true,
msg: "Subscriber added",
id: 28
}
                
subscriber unconfirmed
{
state: false,
msg: "The email "john@doe.com" is already subscribed but not yet confirmed.",
status: 0
}
subscriber confirmed
{
state: false,
msg: "The email "john@doe.com" is already subscribed and confirmed.",
status: 1
}
subscriber unsubscribed
{
state: false,
msg: "The email "john@doe.com" is already already in the database but unsubscribed.",
status: 2
}

Request:

/api.php?method=addEmail&key=API_KEY&listId=2&first-name=John&last-name=Doe&email=john@doe.com&full-cycle=1

Response:

full-cycle
no record in the DB
{
state: true,
msg: "Subscriber added",
result: "http://yourdomain.com/subscription/confirmation-required-2/?u=$unique-code"
}									
                
subscriber unconfirmed
{
state: true,
msg: "The email "john@doe.com" is already subscribed but not yet confirmed.",
result: "http://blog.dev/subscription/email-subscribed-not-confirmed-2/?u=5JFHCK8BPXgo-vZNsq4z83N8loE:mAZaQ6C0XNOFMJLEZLqziA"
}
subscriber confirmed
{
state: true,
msg: "The email "john@doe.com" is already subscribed and confirmed.",
result: "http://blog.dev/subscription/already-subscribed-and-verified-2/?u=5JFHCK8BPXgo-vZNsq4z83N8loE:mAZaQ6C0XNOFMJLEZLqziA"
}
subscriber unsubscribed Attention! in full-cycle mode plugin resubscribes unsubscribed recipients
{
state: true,
msg: "The email "john@doe.com" is already subscribed but not yet confirmed.",
result: "http://blog.dev/subscription/email-subscribed-not-confirmed-2/?u=5JFHCK8BPXgo-vZNsq4z83N8loE:mAZaQ6C0XNOFMJLEZLqziA"
}

Request:

/api.php?method=addEmail&key=API_KEY&listId=2&first-name=John&last-name=Doe&email=john@doe.com&&full-cycle=1&use-excerpts=1

Response:

use-excerpts
no record in the DB
{
state: true,
msg: "Subscriber added",
result: "Please Check Your Email to Confirm Your Subscription!"
}
subscriber unconfirmed
{
state: true,
msg: "The email "john@doe.com" is already subscribed but not yet confirmed.",
result: "This email address is already in our mailing list, however it has not been confirmed. If you would like your verification email resent, please click here."
}
subscriber confirmed
{
state: true,
msg: "The email "john@doe.com" is already subscribed and confirmed.",
result: "If you are not receiving our newsletter, please check your spam filter settings as the email may have been incorrectly flagged as spam and moved to junk mail folder by your email client."
}
subscriber unsubscribed Attention! in full-cycle mode plugin resubscribes unsubscribed recipients
{
state: true,
msg: "The email "john@doe.com" is already subscribed but not yet confirmed.",
result: "Please Check Your Email to Confirm Your Subscription!"
}

Method: getLists

Method has no additional parameters

Request:

api.php?method=getLists&key=API_KEY

Response:

{
    state: true,
    msg: [
        {
            id: 1,
            uid: "qZoKYDA2FmLBdVhFXUqOnyQTQCw",
            name: "default",
            confirmed: 68258,
            unsubscribeURL: "http://yourdomain.com/?newsman=unsubscribe&code=qZoKYDA2FmLBdVhFXUqOnyQTQCw:"
        },
    ...
    ]
}

Method: getListFields

This method returns all the available fields for the list.

Request:

api.php?method=getListFields&listId=2&key=API_KEY
ParamDescription
listIdrequired List id

Response:

{
    state: true,
    msg: {
        fields: [
            "id",
            "ts",
            "ip",
            "email",
            "status",
            "ucode",
            "first-name",
            "last-name"
        ]
    }
}

Method: downloadList

This method allows to retrieve portion or entire list in CSV or JSON formats.

ParamDescription
listIdrequired List id
limitdefault 100. Limit output to N number of rows
offsetdefault 0. Select from Nth row
mapComma separated list of field pairs in format of old-fields-name:new-field-name. For example &map=first-name:FN,last-name:LN will replace the names of the fields to FN and LN accordingly
typeDefault all. Type of seleced subscribers. Possible options: all, confirmed, unconfirmed, unsubscribed
noheader1 or 0, defualt 0. Removes header in CSV output
fieldsComma separated list of fields and link fields to select.
Possible link fields: ‘confirmation-link’, ‘resend-confirmation-link’, ‘unsubscribe-link’.
You can also use +/- modifiers to remove or add fields to the full output. for example:
&fields=+confirmation-link,-last-name,-ts
will add confirmation link to the output and remove last-name and ts fields.
formatcsv or json. Type of output format.
nofile0 or 1, default 0. Don’t force file download. By default method returns content as file download, if you want it to be shown in the browser use this option.
timeInListSelects subscribers which reside in list for specified period of time.
Format: N:TYPE where N is the number of units and TYPE is the type of unit. Available types of units: FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR
For example &timeInList=2:MONTH will select subscribes which subscribed for 2 months.
timeOffsetSelects subscribes which subscription time is greater then specified. Format is MYSQL datetime
Example: &timeOffset=2014-06-19 11:11:47
emailInComma separated list of emails. Selects subscribers data which emails match passed in the parameter

Request:

api.php?method=downloadList&type=confirmed&format=json&nofile=1&offset=0&listId=6&key=API_KEY&map=email:Email,first-name:First_Name,last-name:Last_Name&fields=email,first-name,last-name&limit=50'

Response:

CSV file or JSON:
[
   {"Email":"jon@doe.com","First_Name":"Jon","Last_Name":"Doe"},
   {"Email":"Lee@hughes.com","First_Name":"Lee","Last_Name":"Hughes"}
]

Method: unsubscribe

Unsubscribes reciepients from the list

Request:

api.php?method=unsubscribe&listId=1&emails=john@doe.com&key=API_KEY
ParamDescription
listIdrequired List id
emailsComma separated list of email addresses.
statusUnsubscribe status message. This will be visible to administrator next to subscriber status.
Default: ‘Unsubscibed with API’.

Response:

{
    state: true,
    msg: "Successfully unsubscribed."
}