Welcome to Django Tasker Unisender’s documentation!

https://travis-ci.org/kostya-ten/django_tasker_unisender.svg?branch=master Documentation Status https://api.codacy.com/project/badge/Grade/9fe057e68937477aab1aebd907aa0913 Requirements Status https://badge.fury.io/py/django-tasker-unisender.svg

Requirements

  • Python 3.6+
  • A supported version of Django >= 2.0

Installation

You can get Django Tasker Unisender by using pip:

$ pip install django-tasker-unisender

To enable django_tasker_unisender in your project you need to add it to INSTALLED_APPS in your projects settings.py

INSTALLED_APPS = (
    # ...
    'django_tasker_unisender',
    # ...
)

Add to your settings.py

UNISENDER_API_KEY="<< YOU API KEY>>"

You can get the api key at this link

Add to your models.py

from django_tasker_unisender.models import EmailModel

class Subscribe(EmailModel):

    class UnisenderMeta:
        list_id = 123456789 # Your list id contact on Unisender

Migrate your project

python manage.py makemigrations
python manage.py migrate

Add to your admin.py

from django.contrib import admin
from . import models

class SubscribeAdmin(admin.ModelAdmin):
    list_display = ('email',)

admin.site.register(models.Subscribe, SubscribeAdmin)

Add users automatically

Automatically add users after registration

To do this, specify in the settings settings.py

UNISENDER_AUTO_LIST_ID="<< YOU LIST ID>>"

Attention

You must first create сontact lists

Low-level API Unisender

Usage:

from django_tasker_unisender.unisender import Unisender

unisender = Unisender(api_key="<< api key >>")
lists = unisender.get_lists()
print(lists)
class django_tasker_unisender.unisender.Unisender(api_key: str = None)

Base class to work with low-level API Unisender

create_field(name: str, field_type: str, public_name: str = None) → int

It is a method to create a new user field, the value of which can be set for each recipient, and then it can be substituted in the letter.

Parameters:
  • name – Variable to be substituted. It must be unique and case sensitive. Also, it is not recommended to create a field with the same name as the standard field names (tags, email, phone, email_status, phone_status, etc.) as the importContacts. Admissible characters: Latin letters, numbers, «_» and «-». The first character must be a letter. No spaces are allowed.
  • field_type – Field type Possible options: (string — string, text — one or more strings, number — integer or number with decimal point date — date (the DD.MM.YYYY, DD-MM-YYYY, YYYY.MM.DD, YYYY-MM-DD format is supported) bool — 1/0, yes/no )
  • public_name – Field name. If it is not used, an automatical generation by the «name» field will take place.
Returns:

Identifier field_id

create_list(title: str) → int

Checks the validity of a mobile phone number.

Parameters:title – List name. It must be unique in your account.
Returns:Identifier campaign list
delete_field(field_id: int) → None

It is a method to delete a user field.

Parameters:field_id – Identifier field_id
delete_list(list_id: int) → None

It is a method to delete a list.

Parameters:list_id – Identifier campaign list
exclude(contact_type: str, contact: str, list_ids: list = None) → None

The method excludes the contact’s email or phone number from one or several lists.

Parameters:
  • contact_type – The type of the contact to be excluded is either ’email’ or ‘phone’
  • contact – Email or phone being excluded
  • list_ids – List codes separated by comma from which contacts are being excluded. If it is not specified, contacts will be excluded from all lists.
get_email(email: str) → dict

The method get the contact’s email.

Parameters:email – Email address
Returns:dictionary data
get_fields() → list

Array, each array element is an object with the id, name, type, is_visible and view_pos fields.

get_lists() → list

It is a method to get the list of all available campaign lists.

Returns:Array, each array element is an object dict with the following id and title fields.
subscribe(list_ids: list, fields: dict, double_optin: int = 3, overwrite: int = 0) → int

This method adds contacts (email address and/or mobile phone numbers) of the contact to one or several lists, and also allows you to add/change values of additional fields and tags.

Parameters:
  • list_ids – List codes separated by comma in which a contact is to be added.
  • fields – Dictionaries of additional fields.
  • double_optin – It obtains the value of 0, 3, or 4. (3 by default) (see https://www.unisender.com/en/support/api/partners/subscribe/)
  • overwrite – Field and tag rewriting mode, the number from 0 to 2 (0 by default). It sets what needs to be done in case of existence of a contact (the contact is identified by the email address and/or phone number).
Returns:

Identifier person

update_field(field_id: int, name: str, public_name: str = None) → None

It is a method to change user field parameters.

Parameters:
  • field_id – Identifier field_id
  • name – Field name. It must be unique and case insensitive. Also, it is not recommended to create a field with the same name as the standard field names (tags, email, phone, email_status, phone_status, etc.) as the importContacts method will work incorrectly.
  • public_name – Field name. Name of the «variable for substitution». field in the personal account. If it is not used, an automatically generation by the «name» field will take place. Admissible characters: Latin letters, numbers, «_» and «-». The first character must be a letter. No spaces are allowed.
update_list(list_id: int, title: str) → None

It is a method to change campaign list properties.

Parameters:
  • list_id – Identifier campaign list.
  • title – List name. It must be unique in your account.

Indices and tables