API for merchant

To get started with the API, you need to get an ID and a key. They are available in the Profile section. Hereinafter, the user ID will be denoted as {user} and the access key as {key}. Important! You don't need to include curly braces in the query string!

Interaction with the service is carried out via the HTTP protocol. The request format is pure POST. The result format is JSON. There is no limit on the number of requests. If you need to send a request via JSON POST, do not forget to include the header Content-type: application/json

Add new order

URL: https://api.cpa.moe/comp/add.json?id={user}-{key}

The function allows you to add a new lead as the company, with no order source specified. New lead data is transmitted in a POST request.

The function accepts the following primary data about the lead:

Field Description
offer* Offer ID (required)
name Customer name
phone* Customer phone, digits only (required)
email Customer email
ip* Customer IP-address (required)
ua Customer's browser User-Agent
country Two-letter ISO code of customer's country

Additional parameters for lead creation:

Field Description
us UTM tag utm_source
uc UTM tag utm_campaign
un UTM tag utm_content
ut UTM tag utm_term
um UTM tag utm_medium
currency Three-letter currency ISO code, like USD or EUR
index ZIP code
addr Delivery address. Can contain full address without the ZIP code, or only house and apartment numbers, if the fields below are used.
area Region part of the delivery address
city City part of the delivery address
street Street part of the delivery address
base Unit price in order currency.
count Quantity of goods.
discount Discount on goods as a percentage.
more The amount of the extra cost of the order, for example, margins for express delivery.
comm Order comment.
item The ID of the nested good to be added to the order. If there are several products, it is listed separated by commas.
items An array of nested goods to add to the order, indicating their price. Each product must be represented by an associative array with fields:
  • id - nested good ID
  • price - unit price
  • count - quantity of goods
params Key-value array of custom fields.

Example of a simple lead creation request (shown in JSON for convenience):

{
    "offer": 217,
    "ip": "12.34.56.78",
    "name": "John Doe",
    "phone": "77000000000",
    "country": "kz",
}

Example of creating a lead specifying the array of nested goods (shown in JSON for convenience):

{
    "offer": 217,
    "ip": "12.34.56.78",
    "name": "Jane Doe",
    "phone": "79000000000",
    "country": "ru",
    "items": [
        {
            "id": 135,
            "price": 9900,
            "count": 1
        }
    ]
}

Example of a simple lead creation with custom fields (shown in JSON for convenience):

{
    "offer": 217,
    "ip": "12.34.56.78",
    "name": "John",
    "phone": "77000000000",
    "country": "kz",
    "params": {
        "sirname": "Doe",
        "phonecc": "+7"
    }
}

The result of the function is an associative array:

Field Description
status The result of the operation: ok if successful, error in case of an error
id ID of the created order (if successful)
error Error code: nooffer if no offer ID present, noid if no lead ID present, nophone if no phone present, duplicate if the order with same info was already created, offer if offer was not found, security if user is banned, ban if customer IP or phone is banned, traffic if offer is blocked, db in case of internal error.

Function response example:

{ "status": "ok", "id": 1234 }

List orders

URL: https://api.cpa.moe/comp/list.json?id={user}-{key}&oid=1,2,3

Function shows the list of orders. Request parameters can be sent via both GET and POST.

You can use following parameters for order filtering:

Field Description
oid Internal order ID of AlterCPA Moe or IDs list separated by comma
ids[] Array of internal IDs of AlterCPA Moe.
eid Your CRM order ID or list of IDs separated by comma
eids[] Array of your CRM order IDs.
status Order status code:
  • 1 - processing order
  • 2 - order in hold stage
  • 3 - order is approved
  • 4 - order is cancelled by generic reason
  • 5 - order is cancelled as trash
from
to
Show orders between from and to time. Time is set as UNIX-timestamp. You can use both fields or just one of them. You can use it to load orders to your CRM, but the following field will suit you better.
after The ID of last order after which start listing. You should use this parameter to load orders to your CRM. Simply send the ID of the last received orders and the list will contain only the orders received after that one.

The result of the function is an array of elements with following fields:

Field Description
id Internal order ID of AlterCPA Moe
offer Offer ID
wm Affiliate ID
stage Order status code for affiliate:
  • wait - processing order
  • hold - order in hold stage
  • approve - order is approved
  • cancel - order is cancelled by generic reason
  • trash - order is cancelled as trash
phase Integer order status code for affiliate:
  • 1 - processing order
  • 2 - order in hold stage
  • 3 - order is approved
  • 4 - order is cancelled by generic reason
  • 5 - order is cancelled as trash
status Real order status code in CRM:
  • 1 – New order
  • 2 – Processing
  • 3 – Callback
  • 4 – Hold
  • 5 – Cancelled
  • 6 – Packing
  • 7 – Sending
  • 8 – Transfer
  • 9 – Arrived
  • 10 – Completed
  • 11 – Return
  • 12 – Deleted
reason Reason code for cancel status:
  • 1 – Incorrect phone (trash)
  • 2 – Changed his mind
  • 3 – Did not order (trash)
  • 4 – Requires certificate
  • 5 – Wrong GEO (trash)
  • 6 – Errors or fakes (trash)
  • 7 – Duplicate order (trash)
  • 8 – Ordered elsewhere (trash)
  • 9 – Expensive
  • 10 – Not satisfied with delivery
  • 11 – Could not get through (trash)
  • 12 – Possibly fraud (trash)
  • 13 – Speaks different language (trash)
  • 14 – Product did not fit (trash)
  • 15 – Offer disabled
ip Customer IP address
time Time order was created, UNIX-timestamp
name Customer full name
gender Customer gender. 0 - unknown, 1 - male, 2 - female.
phone Customer phone, digits only
country Two-letter customer country ISO code
index ZIP postal code
addr Delivery address. Can contain full address without the ZIP code, or only house and apartment numbers, if the fields below are used.
area Region part of the delivery address
city City part of the delivery address
street Street part of the delivery address
count Quantity of goods.
items Order contents. Array with item ID as the key, amount and unit price as value.
delivery Delivery service code.
discount Order discount in percent.
currency Three-letter currency ISO-code.
base Unit price in selected currency.
delpr Delivery price in selected currency.
more The amount of the extra cost of the order, for example, margins for express delivery.
price Order total price.
comment Order additional comments.

Function response example:

[
    {
        "id": 13131,
        "offer": 15,
        "offername": "Shiny test offer",
        "wm": 59,
        "stage": "approve",
        "phase": 3,
        "status": 8,
        "reason": 0,
        "ip": "12.34.56.78",
        "time": 1234567890,
        "name": "John Doe",
        "gender": 0,
        "phone": "123456789000",
        "country": "ru",
        "index": "100000",
        "area": "",
        "city": "Moscow",
        "street": "Lenina street",
        "addr": "1",
        "comment": "Will pick up order in three days",
        "count": 6,
        "items": {
            "12": [ 3, 665 ],
            "23": [ 1, 665 ],
            "34": [ 2, 665 ]
        },
        "delivery": 1,
        "discount": 0,
        "currency": "rub",
        "base": "0.00",
        "more": "0.00",
        "delpr": "350.00",
        "price": "4340.00"
    }
]

Set order status

URL: https://api.cpa.moe/comp/status.json?id={user}-{key}&oid=123&status=approve

Function changes order status and can set some order fields. Almost all the parameters can be sent via both GET and POST. Optimal for use in postbacks.

Function can use following input parameters:

Field Description
oid
eid
Order ID to work with. Use oid for internal order ID of AlterCPA Moe or eid for your CRM order ID. Required field. GET only.
status Text representation of order status linked to st* parameters and recognized automatically:
  • Approve: a, accept, accepted, approve, approved, confirm, confirmed, 1
  • Hold: h, hold, holding
  • Cancel: c, d, decline, declined, cancel, cancelled, canceled, reject, rejected, -1
  • Trash: t, trash, error, wrong, bad
sta Order name to recognize as approve
stc Order name to recognize as cancel
stt Order name to recognize as trash
sth Order name to recognize as hold
stw Order name to recognize as processing order
name Customer full name
phone Customer phone, digits only
email Customer email
comment Order additional comments.
country Two-letter country ISO-code
currency Three-letter currency ISO-code
base Unit price or conversion cost in selected currency
count Quantity of goods
delpr Delivery price in selected currency

Order ID and status are required parameters, other fields are optional. The result of the function is an associative array:

Field Description
status The result of the operation: ok if successful, error in case of an error
error Error code: orderid if order ID is missing, edit if no fields changed, access-denied if order ID is incorrect, request-error in case of internal error.

Successful response example:

{ "status" : "ok" }

Error response example:

{ "status" : "error", "error" : "access-denied" }

Edit order info

URL: https://api.cpa.moe/comp/edit.json?id={user}-{key}

Function edits order info. Generally, all the parameters should be send via POST, but some of them can also can be sent via GET.

Function can use following input parameters:

Field Description
oid
eid
Order ID to work with. Use oid for internal order ID of AlterCPA Moe or eid for your CRM order ID. Required field. Can be send via GET.
accept Order approve flag. Use it to approve the order instead of changing status. Can be send via GET.
status Order new status code. Can be send via GET.
  • 1 – New order
  • 2 – Processing
  • 3 – Callback
  • 4 – Hold
  • 5 – Cancelled
  • 6 – Packing
  • 7 – Sending
  • 8 – Transfer
  • 9 – Arrived
  • 10 – Completed
  • 11 – Return
  • 12 – Deleted
To cancel order use status 5 and reason field.
Important! To approve the order use accept=1, not status change!
reason Order cancel reason code required for status=5. Can be send via GET.
  • 1 – Incorrect phone (trash)
  • 2 – Changed his mind
  • 3 – Did not order (trash)
  • 4 – Requires certificate
  • 5 – Wrong GEO (trash)
  • 6 – Errors or fakes (trash)
  • 7 – Duplicate order (trash)
  • 8 – Ordered elsewhere (trash)
  • 9 – Expensive
  • 10 – Not satisfied with delivery
  • 11 – Could not get through (trash)
  • 12 – Possibly fraud (trash)
  • 13 – Speaks different language (trash)
  • 14 – Product did not fit (trash)
  • 15 – Offer disabled
track Parcel tracking code. Can be send via GET.
name Customer full name
phone Customer phone, digits only
email Customer email
index ZIP postal code
addr Delivery address. Can contain full address without the ZIP code, or only house and apartment numbers, if the fields below are used.
area Region part of the delivery address
city City part of the delivery address
street Street part of the delivery address
delivery Delivery service ID
base Unit price in selected currency
delpr Delivery price in selected currency
discount Order discount in percent. Number from 0 to 99.
count Quantity of goods.
items An array of nested goods to set to the order, indicating their price. Each product must be represented by an associative array with fields:
  • id - nested good ID
  • price - unit price
  • count - quantity of goods
more The amount of the extra cost of the order, for example, margins for express delivery. Added to total price after all the discounts.
comment Order additional comments.

Order ID is the only required field, other fields are optional. The result of the function is an associative array:

Field Description
status The result of the operation: ok if successful, error in case of an error
error Error code: orderid if order ID not set, edit if no changes were required, access-denied if order ID is incorrect, request-error in case of internal error.

Successful response example:

{ "status" : "ok" }

Error response example:

{ "status" : "error", "error" : "access-denied" }

Order analytics

URL: https://api.cpa.moe/comp/stats.json?id={user}-{key}&item=date

Function shows order statistics, groupped by the parameter specified. This function gives detailed statistics on the number of orders in each of the statuses.

Function can use following input parameters:

Field Description
item* Required. Parameter to group statistics by:
  • offer - offer ID
  • date - order date
  • hour - order hour
  • stage - processing stage
  • geo - country code
from Statistics start date like YYYY-MM-DD. By default, one week ago is used.
to Statistics end date like YYYY-MM-DD. By default, today is used.
offer Filter by offer ID.
stage Filter by stage ID (not stage name!).
status Filter by status.
hour Filter by hour.
geo Filter by country ISO code.

The result of the function is an associative array. Each element is identified by the ID of grouping field. Each item includes following fields:

Field Description
id Grouping field element ID
name Grouping field element name, if applicable
count Total number of orders
app Percantage of applove without trash orders
apps Percantage of applove including trash orders
cash Distribution of number and total cash amount by currency. Associaive array, key is the currency ISO code, value is pair [ number of leads, cash ].
status Distribution of orders by status. Associaive array, key is the status code, value contains the following fields:
  • count - number of orders in this status
  • cash - distribution of number and total cash amount by currency, as described in previous field.

Function response example:

{
    "20190801": {
        "id": 20190801, // Element ID
        "name": "2019-08-01" // Element name
        "count": 24, // Number of orders
        "app": 100, // Approve percentage
        "apps": 100, // Approve percentage including trash
        "cash": { // Distribution by currency
            "usd": [ // Currency ISO code
                23, // Number of orders
                40477 // Orders total
            ],
            "rub": [ 1, 13990 ]
        },
        "status": { // Distribution by status
            "6": { // Status ID
                "count": 24, // Number of orders
                "cash": { // Distribution by currency
                    "usd": [ 23, 40477 ],
                    "rub": [ 1, 13990 ]
                }
            }
        },
    },
}

Adding audio recording of a call

URL: https://api.cpa.moe/comp/audio.json?id={user}-{key}

To attach a call record to an order, you will definitely need the URL of the record itself and the phone number to which the call was made. The phone number must match the one specified in the order itself. It is highly desirable to also indicate the time of the call and the outgoing number of the operator specified in his profile. The system will try to determine the specific order IDs and change IDs automatically. If it is possible to specify the order ID, it will only be better.

Parameters can be passed in both GET and POST.

Field Description
phone The number indicated in the order card. Required parameter.
operator The operator's phone number specified in his profile
src mp3 ogg wav Link to an audio file of the corresponding format. If the format of the audio file is unknown, src is used, otherwise it is better to specify the specific format. One of these fields is required.
time The time the call was made in Unix Timestamp format. By default, the time of the function is called.
length Call duration in seconds.
user The ID of the user who made the call. By default, the ID is determined by the operator number from the operator parameter.
order Order ID for which the call was made. By default, it is detected automatically 10-15 minutes after adding.
call Call ID to which the call is attached. By default, it is detected automatically 10-15 minutes after adding.

The result of the function is an associative array:

Field Description
status The result of the operation: ok if successful, error in case of an error
id Audio file ID.

Successful response example:

{ "status" : "ok", "id": 1234 }

Error response example:

{ "status" : "error", "error" : "access-denied" }