The REST API provide programmatic access to read and write Ekopost data. Create a new
campaign, envelope, scheduele print & distribution, and more. The REST API identifies applications and users
using Basic Authentication; responses are available in JSON.
Package for .NET Framework available
If you're using .NET Framework you can download and install our nuget package directly, see the section
Tools for more information.
Sandbox - For Developers
During development and testing we recommend using our Sandbox Environment, see the section Sandbox for
more information
Format
The REST API is only using JSON; all requests body should be in JSON and all responses will be JSON. Make
sure you set Request.Header.Content-Type to “application/json”.
Sample Request (RAW)
Content-Type: application/json; charset=UTF-8;
Encoding
UTF8 is the encoding that should be used at all times.
Authorization
The API supports basic, api-key and Oauth2 client credentials authorization, and all requests must be
authorized at all times.
You can use a valid api-key, bearer token or a base64 encoded string based on your user credentials to
build the authorize header value. We recommend that you always use the api-key or Oauth2 approach over the
base64 encoded string, you can create/revoke/reactive/remove api-keys with ease while using the base64
approach your integrations may fail if the password of the used account would ever be changed.
Using an api-key
Set the Request.Header.Authorization value to “api-key key”, to get your key you need to
generate a new API key after you've signed in to your account, you'll be able to generate and manage your
API keys from the account/api section.
First contact hejsan@ekopost.se to request a client_id and a client_secret
When customer has a client_id and a client_secret, these need to be base64 encoded and sent to the API via
POST to receive an access token which is used for subsequent calls. The base64 encoded string should be
created from a string formatted like: "client_id:client_secret".
Create the base64 encoding to be used, replace client_id and client_secret with real values and make sure
there are no trailing newlines and that the string is encoded literally
Then set the Request.Header.Authorization value to “Basic base64encodedString
Sample Request (RAW)
POST https://api.ekopost.se/auth
Authorization: Basic dXNlcm5gaGO6cGFzc3dvctE=
Content-Type: application/json; charset=UTF-8
An access_token is valid for up to 8 hours. A new access_token can be requested any time. If a request to
the API is issued with a non valid access_token a http-response with the HTTP-header 401 is returned such as
HTTP/1.1 401 Unauthorized. With the use of a valid access_token request to the API can be done as the
example below.
Set the Request.Header.Authorization value to “Basic auth_token”, auth_token should be
replaced with a base64 encoded string formatted like: "username:password", where username is your username
and password is your password.
All handled errors will result in bad request (code: 400) and the body will contain an error object for
debugging and development purpose with further information how to validate the request, you can see a list
of error codes in the section Error under Error code values.
Resources not found will result in not found (code: 404) and any unhandled exception will return internal
error (code: 500).
Quick start
To send an envelope you must first create a campaign, then an envelope within that campaign, then create a
content (read: upload a document/attachment) within that envelope, once this is done you'll have to close
both the campaign and the envelope/s to mark them as ready for production, each envelope in the campaign
will be printed & distributed as an individual postal item, the items will be printed & distributed on the
campaign output date.
To schedule print and distribution of a envelope - follow these steps (all requests must be authorized).
Create a campaign Creates an empty campaign in opened state.
Create an envelope
Creates an empty envelope in opened state for the
specified campaign.
Create content (document)
Creates a new document and links it to the
specified envelope.
Create content (attachment)
Creates a new attachment and links it to
the specified envelope.
Change the envelope state to closed
Closes the envelope and marks it
as ready for print and distribution. *Note* the campaign must also be closed.
Change the campaign state to closed
Closes the campaign and marks it
and all related envelopes as ready for print and distribution.
Limitations
The Content object field named data must be a PDF version 1.4, support for later
versions does exist, but printing quality nor result can not be guaranteed without testing. We always
recommend that you send your self a copy of the documents you'll be sending to inspect the result, any
deviations should be reported to our support team.
Page margins & reserved areas
Download our content template to learn about our page margins, reserved page areas and where to place your
destination adress and return adress for optimal visibility.
Envelopes represents a single postal item that will be sent to a single recipient, an
envelope can contain one document and several attachments.
Create envelope
Creates a new envelope with state opened linked to the specified campaign.
POST/campaigns/{campaign_id}/envelopes
Request
URL
Parameter
Type
Description
campaign_id
Guid
Unique id of a campaign within which to create the envelope.
BODY
Parameter
Type
Description
name
String
A friendly name to identify the envelope.
address
Object
Address object that represents the destination, see the section Address objects for valid formats. Remark: In the case of a postal address, the address needs to be embedded into the
uploaded document. The one exception to an embedded address is when the flag 'use_coverpage' is
lit on the postal address object. A 'null' value will be treated as an address of type postal.
postage
String
Postage type denominator, see the section Postage values for
valid values. Remark: For customers registered to our Norwegian production site, this parameter can be
considered redundant as it is ignored.
plex
String
Plex type denominator, see the section Plex values for valid
values.
color
Boolean
Print the content in color (CMYK), if set to false the content will be printed in black and white.
pu
Boolean
Personal delivery, additional service for REK
kb
Boolean
Delivery receipt, additional service for REK
consignor_contact
String
Email for integration with the PostNord-app and receipt mail, additional service for REK
agent
String
Optional For use when agent
unique_id
String
Optional Use with an external id to prevent duplication. Is per customer.
Address object that represents the destination, see the section Address objects for valid formats. Remark: In the case of a postal address, the address needs to be embedded into the
uploaded document. The one exception to an embedded address is when the flag 'use_coverpage' is
lit on the postal address object. A 'null' value will be treated as an address of type postal.
postage
String
Postage type denominator, see the section Postage values for
valid values.
plex
String
Plex type denominator, see the section Plex values for valid
values.
color
Boolean
Print the content in color (CMYK), if set to false the content will be printed in black and white.
state
String
State type denominator, see the section State values for valid
values.
state_changed_at
Date
Date in UTC format representing the date when the envelope state was changed.
created_at
Date
Date in UTC format representing the date when the envelope was created.
(Only available for mailings with PostageType REK)
Init Created, not booked yet
INFORMED Booked at Post Nord but not sent yet
EN_ROUTE Sent and on its way to the delivery service point
AVAILABLE_FOR_DELIVERY Delivered to the delivery service point and ready to be collected
RETURNED Has been returned
DELIVERED Has been delivered/collected
DoneReturned After RETURNED, we send a notification mail to the user who created the mailing.
Done After DELIVERED we send a notification mail to the user who created the mailing.
After the states Done or DoneReturned the tracking of the mailing stops.
Optional State type denominator, see the section
State
values
for valid values.
Get failed envelopes
Gets a list of all failed envelopes within a campaign. Typically used to find fail reason for original
address object when envelope has been rescheduled
Content can either be a document or an attachment linked to an envelope, an envelope
can only have one document linked to it, but several attachments, please read the section Limitation for further information.
Create content
Creates a content either as a document or attachment linked to the specified envelope, only one document
can be linked to an envelope.
Unique id of a campaign within which the envelope exists.
envelope_id
Guid
Unique id of an envelope to add the content to.
BODY
Parameter
Type
Description
data
String
The original file's data as a base64encoded string.
mime
String
The original file's mime type.
length
Int
The original file's size in bytes.
type
String
Content type denominator, see the Type values section for
valid values.
return_address
Boolean
Optional Set as true to add a return address on the upper left corner of the letter. (The
address that will show is the return address on your account.)
address
Object
Optional Address object that represents postal destination of returned letters, see the
section Address objects. Object (postal) is the valid object. Remark: For this address to be used as a return address on the letter, return_address must
also have the value 'true'
The campaign is opened, you can add envelope, modify or change state to cancelled.
closed
The campaign is marked as ready for production and can not be modified.
transferred
The campaign and all linked envelopes has been transferred to our production facility.
completed
The campaign and all linked envelopes has been printed and posted.
cancelled
The campaign has been closed and all linked envelopes will not be printed or distributed.
failed
The campaign could not be produced in our facility, contact our customer service for further
details.
Envelope
Representation of an envelope that will be posted.
Object
BODY
Parameter
Type
Description
id
Guid
The envelope object's unique id.
name
String
A friendly name to identify the envelope.
address
Object
Address object that represents the destination, see the section
Address
objects
for valid formats. Remark: In the case of a postal address, the address needs to be embedded into the
uploaded document. The one exception to an embedded address is when the flag 'use_coverpage' is
lit on the postal address object. A 'null' value will be treated as an address of type postal.
postage
String
Postage type denominator, see the section Postage values for
valid values. Remark: For customers registered to our Norwegian production site, this parameter can be
considered redundant as it is ignored
plex
String
Plex type denominator, see the section Plex values for valid
values.
color
Boolean
Print the content in color (CMYK), if set to false the content will be printed in black and white.
state
String
State type denominator, see the section State values for valid
values.
pu
Boolean
Personal delivery, additional service for REK
consignor_contact
String
Email for integration with the PostNord-app and receipt mail, additional service for REK
state_changed_at
Date
Date in UTC format representing the date when the envelope state was changed.
created_at
Date
Date in UTC format representing the date when the envelope was created.
Your content will be delivered within one working day after it's been printed and posted.
economy
Your content will be delivered within four working days after it's been printed and posted.
rek
Mailings that needs to be signed by the recipient before hand out.
protected
Mailings to recipients who have protected identities.
Plex values
VALUES
Parameter
Description
simplex
We will only print on the front of each paper sheet.
duplex
We will print on both the front and back of each paper sheet.
State values
VALUES
Parameter
Description
opened
The envelope is in opened state, you can add content, modify or cancel the envelope.
closed
The envelope is in closed state, it's marked as ready for print & distribution.
transferred
The envelope has been transferred to our production facility, and can no longer be modified or
cancelled.
printed
The envelope has been printed in our production facility.
posted
The envelope has been posted.
cancelled
The envelope has been cancelled, and will not be printed or distributed.
failed
The envelope could not be produced in our facility, contact our customer service for further
information.
Address
Object (postal)
The envelopes content will be printed and will be sent with regual postal mail. Note: The address is
still
required to be embedded inside the document unless the use_coverpage flag is used.
In case of Registered mail/REK, certain limitations apply to the different address rows. name and street
have a max
limit of 35 characters/row and postal_code a limit to five digits only (with or without blankspaces).
BODY
Parameter
Type
Description
$type
String
Denominator for the address type, should always be set to 'postal'. Remark: this parameter must come first in the json object.
name
String[]
The recipient's name, each string in the array is considered to be a address line.
street
String[]
The recipient's street name, each string in the array is considered to be a address line.
Type 'invoice.renewal' will soon be supported by Kivra.
The content will be sent to kivra inbox (einbox_kivra) owned by the recipient, if the einbox doesn't exist
the envelope will be printed and posted instead.
URL
Parameter
Type
Description
$type
String
Denominator for the address type, should always be set to 'einbox_kivra'. Remark: this parameter must come first in the json object.
recipient
String
The recipient of the einbox's social security number, to where the contents of the envelope will
be sent.
subject
String
The value will be displayed as subject in the recipient's e-inbox if supported. Remarks: if a template has been specified this value will be ignored and the stored
subject of the template will be used instead.
sender_id
String
Optional to set other sender then the default.
kivra_type
Int
0: Letter (Default), 1: Invoice, 2: Letter Salary, 3: Booking, 4: Invoice Renewal
booking
Object
Parameter
Type
Description
title
String
Title for the booking
start_time
Date
The bookings start time
end_time
Date
(Optional) The bookings end time
location
String
(Optional) Location address
description
String
(Optional) Description
info_url
String
(Optional) Url
invoice
Object
Parameter
Type
Description
reference
String
Tenants own reference
payable
Boolean
If should be payable
currency
String
Currency used in specifying total_owed. Ex. SEK, DKK, NOK
due_date
Date
Date when this Invoice is due
total_owed
String (float)
The total amount owed according to the invoice. If payable equals true this must be a
non negative number that's greater than "0"
use_ocr
Boolean
True: OCR, False: reference
use_bg
Boolean
True: BG, False: PG
account
String
Tenant's account number
payment_reference
String
The reference number used for paying. This can be maximum 25 characters long
variable_amount
Boolean
Toggles whether the user may choose to pay only a portion of the total_owed amount or
whether the user must always pay the complete total_owed amount
min_amount
String (float)
The minimum amount that can be paid when variable_amount equals true. Note that this is
a soft limit, so whenever variable_amount is true the user will be able to choose freely
the amount to be paid, but it may be warned if the amount paid is inferior to min_amount.
min_amount must be greater than "0" and less than "total_owed".
The content will be sent to a digital inbox (einbox) owned by the recipient, if the einbox doesn't exist
the envelope will be printed and posted instead. Used for Digipost (Norway) and MinaMeddelanden (Sweden).
BODY
Parameter
Type
Description
$type
String
Denominator for the address type, should always be set to 'einbox'. Remark: this parameter must come first in the json object.
recipient
String
The recipient of the einbox's social security number, to where the contents of the envelope will
be sent.
template
String
The id of a predefinied ekopost template. The stored subject and content of the template will be
used instead of any subject/content specified in the request.
subject
String
The value will be displayed as subject in the recipient's e-inbox if supported. Remarks: if a template has been specified this value will be ignored and the stored
subject of the template will be used instead.
content
String
The specified content will be displayed as html/text message in the recipients e-inbox if
supported. Remarks: if a template has been specified this value will be ignored and the stored
content of the template will be used instead.
The content will be sent to a digital inbox (einbox) ,if it exist, owned by the recipient and also to a
given email, if the einbox doesn't exist the document can be signed by bank-id login.
BODY
Parameter
Type
Description
$type
String
Denominator for the address type, should always be set to 'einbox_signer'. Remark: this parameter must come first in the json object.
info_mail
String
Email inbox that should receive information and the covenant document when all parties has signed
the document.
sender_id
String
Optional to set other sender then the default.
signers
Object[]
Signer object that represents the signers.
signers.email
String
Email address where the link for singing the document will be sent.
signers.recipient
String
The recipient's social security number.
signers.issuer
Boolean
The issuer of the signing document Remark: Can be true for one signer.
Intermediator type denominator, see the section Intermediator values for valid values. Remark: If the recipient is using Ekopost to receive eletronic documents or the
intermediator is not found or unkwon, set the value to 'null'.
The envelope's content will be sent as an invoice.
BODY
Parameter
Type
Description
$type
String
Denominator for the address type, should always be set to 'einvoice_mastercard'. Remark: this parameter must come first in the json object.
sender_id
String
Your customer's id number/string
kid
String
The KID of the invoice.
credit_account
String
The credit account of the invoice.
issuer
String
The issuer of the invoice.
shipment_id
Guid
The shipment id of the invoice.
account_number
String
The account number of the invoice.
amount
Double
The amount of the invoice.
due_date
String (DateTime)
The due date of the invoice.
payment_type
String
The payment type of the invoice. One of:
EFAKTURA,
EFAKTURA_AND_AVTALEGIRO,
EFAKTURA_AND_EXTERNAL_AVTALEGIRO,
AVTALEGIRO
document_type
int
The document type of the invoice. One of:
0 = INVOICE,
1 = CREDIT_NOTE,
2 = REMINDER,
3 = COLLECTION_NOTICE,
4 = DUNNING,
5 = PAYMENT_REQUEST,
6 = ENFORCEMENT_WARNING
efaktura_identifier
String
The efaktura identifier of the invoice.
social_security_number
String
The social security_number of the invoice.
e_faktura_reference
String
The efaktura reference of the invoice.
minimum_amount
Double (nullable)
The minimum amount of the invoice.
brand_name
String (nullable)
The brand name of the invoice. Must be set when sending EFAKTURA, EFAKTURA_AND_AVTALEGIRO,
EFAKTURA_AND_EXTERNAL_AVTALEGIRO
e_faktura_url
String (nullable)
The external url of the invoice.
collection_notice_notification_email
String (nullable)
The collection notice notification email.
collection_notice_notification_mobile_phone
String (nullable)
The collection notice notification mobile phone.
atg_notification
Bool
Notification active bool.
atg_notification_text
String (nullable)
The atg notification text of the invoice.
atg_abbreviated_name
String (nullable)
The atg abbreviated name of the invoice.
atg_external_reference
String (nullable)
The atg external reference of the invoice.
{
"$type": "einvoice_mastercard",
"sender_id": "12345",
"kid": "",
"credit_account": "11223344556",
"issuer": "987654321",
"shipment_id": "4357b0f9-2d83-4782-ab24-aa590c7027f7",
"account_number": "22113344665",
"amount": 100.00,
"due_date": "2024-01-01",
"payment_type": "EFAKTURA",
// only one of the three following should be set, depending on if you send efaktura, avtalsgiro etc.
"efaktura_identifier": "789456123", // use the reachable api to get the efaktura identifier if you don't already have it.
"social_security_number": null,
"e_faktura_reference": null,
"minimum_amount": null,
"brand_name": null,
"e_faktura_url": null,
"collection_notice_notification_email":null,
"collection_notice_notification_mobile_phone": null,
// atg
"atg_notification": false,
"atg_notification_text": null,
"atg_abbreviated_name": null,
"atg_external_reference": null"
}
or shorter version for EFAKTURA:
{
"$type": "einvoice_mastercard",
"sender_id": "12345",
"kid": "",
"credit_account": "11223344556",
"issuer": "987654321",
"account_number": "22113344665",
"amount": 100.00,
"due_date": "2024-01-01",
"payment_type": "EFAKTURA",
// only one of the three following should be set, depending on if you send efaktura, avtalsgiro etc.
"efaktura_identifier": "789456123",
"minimum_amount": null
}
Transaction
The envelopes transaction information when it changed and to what state.
Object
BODY
Parameter
Type
Description
state
String
State type denominator, see the section State values for valid
values.
state_changed_at
Date
Date in UTC format representing the date when the campaign state was changed.
Bad requests with http response code 400 does contains an error object with futher information about the
bad request.
Object
BODY
Parameter
Type
Description
error_code
String
Code that represents the error that occured.
error_message
String
Description about what error occured.
developer_message
String
Further description about the error for developers.
{
"error_code": "0",
"error_message": "Invalid basic authentication token.",
"developer_message": "Please verify that the account is activated and the username and password are valid."
}
Error codes
Error code values
VALUES
Value
Description
0
Invalid basic authentication token.
100A
The envelope must contain atleast one (1) document before being closed.
100B
The envelope must contain atleast one (1) markup before being closed.
101
A campaign must contain atleast one (1) envelope before being closed.
102
All envelopes inside a campaign must be closed before closing the campaign.
103
An envelope may only contain one (1) document.
104
An envelope may only contain content with mime of 'application/pdf'.
105
Could not extract or identify a postal address in the envelopes main documents.
106
Campaign was not found.
107
Could not open the main document content or find any pages.
108
An envelope may only contain content of type 'attachment' with mime set to 'application/pdf'.
109
An envelope may only contain content of type 'markup' with mime set to 'application/xml'.
110
An envelope may only contain one (1) markup.
111
Envelope was not found.
112
Specified country is not a valid ISO 3166-1 encoded alpha-2 code.
113
You have exceeded your credit limit for the month, please contact our customer service to adjust
your credit
limit.
114
The searchparams is null.
115
The searchparams is invalid.
116
The timespan is invalid.
117
The document size is invalid.
118
The attachment size is invalid.
119
Missing recipient.
120
Missing email
121
Can not create more envelopes in campaign
122
One signer needed
123
Email address contains invalid characters.
124
FUI-number is not registrered
125
No applicants registrered for this FUI
126
Not unique
127
Invalid data
128
Wrong mime for sms. Mime should be 'text/plain'
129
Empty data field
130
Sms text message not encoded into base64
131
Sms recipients contains invalid phone number.
132
Sms does not contain any recipients
133
Sms "FromName" is null or empty.
134
Sms too many recipients (100 000 is the max limit)
135
Address validation error, error contains more details such as "Name too long (max 35 characters)"
136
Invalid contract, error contains more details.
137
Document content not found on the specified envelope
138
Recipient can not be the same as the issuer
139
Recipient must have a valid valuer
140
No setup for protected mailing, contact hejsan@ekopost.se to get started with protected mailing.
141
Invalid contract
142
Reply mail template missing
143
More than 50 documents over 8Mb sent current day
Tools
Package for .NET Framework
Ekopost is quick and easy to integrate in a .NET environment using our nuget package, the package uses a fluent interface to
schedule print & production.
Installation
PM > Install-Package Ekopost
Usage
Using the Ekopost nuget package
Table of contents
5 step walkthrough
the minimum required steps needed to schedule an envelope
initialize
create a new campaign
create a new Envelope
create a new Content
close the campaign and envelope
cancel and review objects
creating an Ebank Address object
5 step walkthrough
Initialization
Setting up the Ekopost class to target your account.
In order to integrate with Ekopost you must first provide an API key that is linked to your account, this key can be found in the portal https://secure.ekopost.se. Once you have your key you can use it as a parameter to instantiate an Ekopost object as seen in [CODE EXAMPLE 1] below
[CODE EXAMPLE 1] -initialize
- - - - - - - - - - - - - - - - - - - - -
using Ekopost.Contracts;
.
.
.
1 var eko = new Ekopost.Ekopost("apikeystring");
.
.
.
- - - - - - - - - - - - - - - - - - - - -
Now when we have an Ekopost object, [eko], there are 3 important functions to note:
eko.CampaignSet.Create();
eko.EnvelopeSet.Create(Guid campaignId);
eko.ContentSet.Create(Guid campaignId, Guid envelopeId);
In this tutorial we will go through each of the objects created by these functions with example of how to use them and in the process we will have scheduled our first mail for delivery using the Ekopost nuget package.
Content can be thought of as the letter that you wish to send. That letter needs to be put in an envelope and a campaign can contain multiple envelopes. When we code this using the nuget package we do it in reverse and create the campaign first, then the envelope and finally the content. Lets get started with the campaign
Campaign
[CODE EXAMPLE 2] -create a new campaign
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 var newCampaign = new Campaign("myFirstCampaign","", DateTime.Now.AddHours(2));
2
3 var campaignSet = eko.CampaignSet.Create();
4
5 var registeredCampaign = campaignSet
6 .Create(newCampaign)
7 .Resource;
.
.
.
- - - - - - - - - - - - - - - - - - - - -
first we create a campaign object on line 1. In the example it has been given a name [myFirstCampaign], providing a blank cost center and schedules the send outs to two hours from now.
Next we use the first function mentioned above to create a CampaignSet object, this is what we use when we want to manipulate campaigns.
Note that no interaction with Ekopost has yet occurred, on the line 6 however an API call is made by calling the Create() function campaignSet. This function return a wrapper object with metadata on the API call, the Resource property contains the registered campaign. We are interested in the returned campaign object because it contains an Id that needs to be referenced in our next step.
Envelope
[CODE EXAMPLE 3] -create a new Envelope
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 var postalAddress = new AddressPostal(
2 new[] { "Johnny Doh" },
3 new[] { "Ekovägen 12" },
4 "43215",
5 "Ekostaden",
6 "SE");
7 var envelope = new Envelope("firstLetter", postalAddress, Postage.Economy, Plex.Simplex, false);
8 var envelopeSet = eko.EnvelopeSet.Create(registeredCampaign.Id);
9 var registeredEnvelope = envelopeSet
10 .Create(envelope)
11 .Resource;
.
.
.
- - - - - - - - - - - - - - - - - - - - -
an envelope needs a destination, so we start by making an address object on line 1-6. There are multiple address types however this tutorial covers only a postal address type. Now when we have an address we can use it as a parameter when creating an envelope as is seen on line 7. Once again we create a Set item (line 8), this time the EnvelopeSet, so that we can manipulate envelopes in Ekopost, note that we need to use the Id of the campaign item [registeredCampaign] we received in [CODE EXAMPLE 2]. Just like before we make an API call and register our envelope with Ekopost via the Create() method on line 9-11.
Content
[CODE EXAMPLE 4] -create a new Content
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 var content = new Content(ContentType.Document, "~path/to/file/on/disk/aletter.pdf");
2 var contentSet = eko.ContentSet.Create(registeredCampaign.Id, registeredEnvelope.Id);
3 contentSet.Create(content);
.
.
.
- - - - - - - - - - - - - - - - - - - - -
this is where we upload our letter, what we call content. It is required that an envelope contains a document type Content, this is the main content of any envelope, so on line 1 we create such content. In this example we point to the file that we want to upload from disk by using a path parameter. Next, line 2, we use our last Set item, namely that of a ContentSet, to manage our content, this time we need to supply the campaign [registeredCampaign] id from [CODE EXAMPLE 2] and also the envelope [registeredEnvelope] Id from [CODE EXAMPLE 3]. Finally on line 3 we make the API call.
OK all set? Not quite!
More envelopes and more content can be created as desired, once done we need to mark the campaign and the envelope as ready for delivery
Close
[CODE EXAMPLE 5] -close the campaign and envelope
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 envelopeSet.Close(registeredEnvelope.Id);
2 campaignSet.Close(registeredCampaign.Id);
.
.
.
- - - - - - - - - - - - - - - - - - - - -
by using our Set objects we call the close function on both envelopes and campaigns, this will mark them as ready for our system to send them on to their destination. Note that once they are closed you may no longer modify them, you may however cancel, provided you do it before the scheduled send out time.
Cancel and Review
[CODE EXAMPLE 6] - cancel and review objects
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 envelopeSet.Cancel(registeredEnvelope.Id);
2 campaignSet.Cancel(registeredCampaign.Id);
3 envelopeSet.List().Resource;
4 campaignSet.List().Resource;
.
.
.
- - - - - - - - - - - - - - - - - - - - -
Line 1 and 2 shows how to cancel envelopes and campaigns respectively
line 3 and 4 shows how to retrieve a collection of envelopes and campaigns respectively. The List() function also accepts parameters to filter the returned result.
envelopeSet has string name and string state as filter parameters and
campaignSet has DateTime? start, DateTime? stop, string name and string state.
Using the Ebank Address object
When sending an invoice directly to a customers bank account, the Ebank address should be used. this object (ebankAddress) will replace the postalAddress object from [CODE EXAMPLE 3] when creating an Envelope.
[CODE EXAMPLE 7] - Creating an Ebank Address object
- - - - - - - - - - - - - - - - - - - - -
.
.
.
1 var ebankAddress = new AddressEbank(
2 "5568384118.BNK.SE",
3 "556838-4118",
4 "No Ink AB",
5 "556838",
6 ReferenceTypes.Ocr,
7 "0000556838411800",
8 "5568-3841",
9 false,
10 499.99M,
11 Convert.ToDateTime("2019-09-17T00:00:00"),
12 Convert.ToDateTime("2019-09-20T00:00:00"));
.
.
.
- - - - - - - - - - - - - - - - - - - - -
The parameters used when creating an Ebank address are further described in the Object (ebank) section above
Sandbox
The url for connecting to our sandbox environment is http://api.sandbox.ekopost.se
Remarks:
Sandbox do not use https!
Nothing that uploaded to sandbox will be sent to end customers.
3. When you have created your sandbox account, you will automatically be signed in and you can immediately
manually start uploading letter for testing or start using our API (http://api.sandbox.ekopost.se)
with your user information that has been sent to your e-mail you entered when registering.
Webhooks
Set up Webhooks to receive status when campaign is completed.
You can access webhook-setup in secure API-settings menu here.
Webhooks allow you to build or set up integrations which subscribe to certain Ekopost events. When one of
those events is triggered, we'll send a HTTP POST payload to the webhook's configured URL. Once installed,
the webhook will be triggered each time one or more subscribed events occurs.
Event
Webhooks are only subscribed to the campaign completed event for now. For example, if you subscribe to
webhooks event you'll receive a payload every time a campaign is completed and statuses for all envelopes in
the campaign.
Payloads
You'll get a specific payload with the envelopes id and status information.
Delivery header
HTTP POST payloads that are delivered to your webhook's configured URL endpoint will contain one special
header:
X-Ekopost-Signature The HMAC hex digest of the response body. The HMAC hex digest is generated using
the sha1 hash function and the secret as the HMAC key.
private IRestResponse Get(string url)
{
var client = new RestClient();
var request = new RestRequest($"{_host}{url}");
request.Method = Method.GET;
request.AddHeader("Authorization", $"api-key {_apiKey}");
request.AddHeader("Content-Type", "application/json; charset=UTF-8");
return client.Get(request);
}
Post method used in the examples
private IRestResponse Post(string url, string requestBody = null)
{
var client = new RestClient();
var request = new RestRequest($"{_host}{url}").AddJsonBody(requestBody);
request.Method = Method.POST;
request.AddHeader("Authorization", $"api-key {_apiKey}");
request.AddHeader("Content-Type", "application/json; charset=UTF-8");
return client.Post(request);
}
SMS
var body = new
{
// Required
From = "Test", // Sender name or phone number
Recipient = "+46701010101", // Recipient phone number
Text = "Test text", // Sms text content
Title = "Dispatch title", // Description of the sms
// Optional
Cost_Center = "Tester", // Cost center
Unique_Id = "ref-22345-3", // Unique id to prevent duplicates
WebhookUrl = "https://webhooks.codeexamples.abc/sms" // Where to receive status webhook
};
var result = Post("dispatch/sms/", JsonConvert.SerializeObject(body, Formatting.None));
/* ToDo: Check result status */
dynamic response = JsonConvert.DeserializeObject(result.Content);
/* ToDo: Check response status */
// Poll sms by Id
var pollByIdResult = Get($"dispatch/sms/{response.id.ToString()}");
// Poll sms by UniqueId
var pollByUniqueResult = Get($"dispatch/sms/unique/{response.unique_id.ToString()}");
We will add an envelope to the mailing during production.
This feature needs to be set up per customer, contact hejsan@ekopost.se for more information.
Create reply mail
Reply mail are created the same way as regular postal mailings with these exceptions
1. Campaign body should have "replymail" set to "true"
// Create campaign
var campaignBody = new
{
name = "Replymail example",
output_date = DateTime.Now,
cost_center = "",
replymail = true // 1.
};
var createCampaignResult = Post($"/campaigns/", JsonConvert.SerializeObject(campaignBody, Formatting.None));
var createCampaignObject = JsonConvert.DeserializeAnonymousType(createCampaignResult.Content, new { id = "" });
2. A replymail-template should be added as an attachment marked replymail
// Attach the reply mail template
bytes = File.ReadAllBytes(@"File\Mall för svarsbrev för Svarspost ver 2.pdf");
fileBase64 = Convert.ToBase64String(bytes);
var attachmentBody = new
{
data = fileBase64,
mime = "application/pdf",
length = 1024,
type = "replymail", // 2.
};
createContentResult = Post($"campaigns/{createCampaignObject.id}/envelopes/{createEnvelopeObject.id}/content",
JsonConvert.SerializeObject(attachmentBody, Formatting.None));
createContentObject = JsonConvert.DeserializeAnonymousType(createContentResult.Content, new { id = "" });
Protected mailing
This feature needs to be set up per customer, contact hejsan@ekopost.se for more information.
Create protected mailing
Protected mailings are created the same way as regular postal mailings with these exceptions
1. Body of create envelope request should have postage = "protected"
2. and an address object of type "protected"
3. which should have a recipient in the form of ssn/pnr
// Create envelope
var envelopeBody = new
{
name = "A protected letter",
postage = "protected", // 1
plex = "simplex",
color = false,
address = new JObject
{
{ "$type", "protected" }, // 2
{ "recipient", "998811-XXXX" }, // 3
{ "use_coverpage", false}
}
};
var createEnvelopeResult = Post($"campaigns/{createCampaignObject.id}/envelopes",
JsonConvert.SerializeObject(envelopeBody, Formatting.None));
var createEnvelopeObject = JsonConvert.DeserializeAnonymousType(createEnvelopeResult.Content, new { id = "" });
If use_coverpage is set to false, the only thing that should be visible inside the address area is the recipients ssn/pnr.