API for Sending Letters via Swiss Post

Pingen’s powerful, fully scalable Letter API enables your software solution to send letters via Swiss Post and DHL. Our SDKs allow for fast, easy integration.

Post API for sending letters via Swiss Post and DHL
Benefits for Developers

Send Letters Automatically

Pingen’s Post API enables easy software integrations to automatically send letters via Swiss Post and DHL.

Swiss Post API

Free API

We’re passionate about helping you automate processes. That’s why we provide our API to all customers free of charge.

Powerful SDKs

Powerful SDKs

Send letters via Swiss Post and DHL in record time with our SDKs for PHP, Python and .Net.

Payment Forms

Supported Payment Forms

Automatic printing as a Swiss QR invoice or with SEPA payment slips in Germany and Austria.

Post API from Developers for Developers

From Developers for Developers

All of Pingen’s features are also available via our Post API and explained in detail in our documentation.

Swiss Post Track & Trace

Track & Trace

Pingen provides detailed status information and real time progress updates for each letter submitted via API.

Generate Revenue

Generate Revenue

By reselling postal letters, integrators can unlock an exciting, new opportunity to generate additional revenue.

Fast, powerful, user-friendly Post API

Pingen’s Letter API is designed to be flexible and straightforward, making it easy to integrate in no time. In addition to the user-friendly documentation, we also provide code examples to help you get started in no time.

import pingen2sdk

pingen2sdk.client_id = "YOUR_OAUTH2_CLIENT_ID"
pingen2sdk.client_secret = "YOUR_OAUTH2_CLIENT_SECRET"

resp = pingen2sdk.OAuth.get_token( 
    grant_type = "client_credentials",
    scope = "letter batch webhook organisation_read",
)

try:
    print(
         pingen2sdk.FileUpload(pingen2sdk.APIRequestor(resp["access_token"]))
         .request_file_upload()
         .data
    )
except pingen2sdk.error.PingenError as e:
    print(e.status_code)
    print(e.json_body)

require __DIR__ . '/vendor/autoload.php';

$provider = new \Pingen\Provider\Pingen(
   array(
   'clientId' => 'YOUR_OAUTH2_CLIENT_ID',
   'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET'
)
);

$access_token = $provider->getAccessToken('client_credentials');

$lettersEndpoint = (new \Pingen\Endpoints\LettersEndpoint($access_token))
    ->setOrganisationId('INSERT_YOUR_ORGANISATION_UUID_HERE');

$lettersEndpoint->uploadAndCreate(
   (new \Pingen\Endpoints\DataTransferObjects\Letter\LetterCreateAttributes())
       ->setFileOriginalName('your_original_pdf_name.pdf')
       ->setAddressPosition('left')
       ->setAutoSend(false),
   fopen('path_to_your_original_pdf_name.pdf', 'r')
);

import json
import requests

url_file_upload = 'https://api.v2.pingen.com/file-upload'
url_letters = 'https://api.v2.pingen.com/organisations/YOUR_ORGANISATION_UUID/letters'
access_token = 'INSERT_YOUR_ACCESS_TOKEN_HERE'

response = requests.get(url_file_upload, headers =
    'Authorization': 'Bearer {}'.format(access_token),
})
data = json.loads(response.text)['data']
file_url = data['attributes']['url']
file_url_signature = data['attributes']['url_signature']

file = open('path_to_your_file.pdf', 'rb')
requests.put(file_url, data=file)
file.close()

payload = {
    'data': {
         'type': 'letters',
         'attributes': {
              'file_original_name': 'your_filename.pdf',
              'file_url': file_url,
              'file_url_signature': file_url_signature,
              'address_position': 'left',
              'auto_send': False
         }
    }
}
requests.post(
    url_letters,
    json.dumps(payload),
    headers = {
         'Content-Type': 'application/vnd.api+json',
         'Authorization': 'Bearer {}'.format(access_token)
    })

$accessToken = 'INSERT_YOUR_ACCESS_TOKEN_HERE';
$organisationUuid = 'YOUR_ORGANISATION_UUID';
$filePath = 'path_to_your_file.pdf';
$fileName = 'your_filename.pdf';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.pingen.com/file-upload");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $accessToken"]);

$response = curl_exec($ch);
curl_close($ch);

$responseData = json_decode($response, true);
$fileUploadUrl = $responseData['data']['attributes']['url'];
$fileUrlSignature = $responseData['data']['attributes']['url_signature'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $fileUploadUrl);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, fopen($filePath, 'r'));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));

$response = curl_exec($ch);
curl_close($ch);

$letterData = [
   'data' => [
       'type' => 'letters',
       'attributes' => [
           'file_original_name' => $fileName,
           'file_url' => $fileUploadUrl,
           'file_url_signature' => $fileUrlSignature,
           'address_position' => 'left',
           'auto_send' => false,
           'delivery_product' => 'fast',
           'print_mode' => 'simplex',
           'print_spectrum' => 'color'
       ]
   ]
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.pingen.com/organisations/$organisationUuid/letters");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($letterData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
   "Content-Type: application/vnd.api+json",
   "Authorization: Bearer $accessToken"
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

curl \
       -X GET "https://api.v2.pingen.com/file-upload" \
       -H "Authorization: Bearer INSERT_YOUR_ACCESS_TOKEN_HERE"

# Extract data.attributes.url and data.attributes.url_signature from response

curl -X PUT -T path_to_your_file.pdf "INSERT_URL_FROM_INITIAL_CURL_REQUEST"

curl \
       -X POST "https://api.v2.pingen.com/organisations/INSERT_YOUR_ORGANISATION_UUID_HERE/letters" \
       -H "Content-Type: application/vnd.api+json" \
       -H "Authorization: Bearer INSERT_YOUR_ACCESS_TOKEN_HERE" \
       --data-binary @- << EOF
       {
           "data": { \
               "type": "letters", \
               "attributes": { \
                   "file_original_name": "your_filename.pdf", \
                   "file_url": "INSERT_URL_FROM_INITIAL_CURL_REQUEST", \
                   "file_url_signature": "INSERT_URL_SIGNATURE_FROM_INITIAL_CURL_REQUEST", \
                   "address_position": "left", \
                   "auto_send": false, \
                   "delivery_product": "fast", \
                   "print_mode": "simplex", \
                   "print_spectrum": "color" \
               } \
       } \
   }
EOF

API Highlights

Online Mail Service API for Letters

Sending letters via Pingen’s Post API is as easy as sending a standard email. Our API is digital and fully scalable.

API Documentation
Learn more
Online letter mailing within Switzerland
Automatic Document Validation

Pingen automatically checks all submitted PDFs if they comply with the requirements of postal letters. If any requirements are not met, Pingen provides options to fix them directly via the API.

Send letters automatically
Digital Returns Processing

If the Swiss Post or DHL fail to deliver any letters, they are automatically captured using the Pingen DMC, destroyed in a controlled manner, and reported via webhooks. This way, undeliverable letters are always processed digitally.

Detailed Track & Trace
Sandbox/Test Environment

Pingen offers a staging environment to all developers to ensure that integrations are easily and conveniently tested in a sandbox. All features of Pingen are available in the sandbox but no letters will actually be sent.

Digital Returns Processing
Detailed Pricing Calculator

Use the pricing calculator endpoint to check the price of a letter in advance. This way, you can always determine the full costs before sending any letter.

Real-time status updates via webhooks

Pingen provides automatic webhook notifications for key events, ensuring timely updates on letter status. You'll be alerted instantly about sent letters, issues, or undeliverable items. This allows for quick reaction, without the need to actively monitor our API.

Within Pingen's webhook management, you gain access to detailed request information, including payload and system responses. This allows for quick problem identification and solving with minimal effort.

Shipping cost statistics
Pingen PHP Library

Easy Integration with the Pingen PHP Library

The Pingen PHP Library offers everything you need to integrate our API and send letters via Swiss Post and DHL. Pingen has already done the work for all PHP developers. Coming soon, we’ll release our SDKs for all other developers as well. 🚀

More than just a Lettershop API

Our Post API offers much more than the classic API used by lettershops or mail service providers. With Pingen, you gain access to a fast-growing and international service that helps you send letters globally for the best price.

Local Mail Service Provider via Swiss Post

Local Mail Service Provider

Already today, letters are being printed and sent locally in Switzerland, Austria, Germany, Holland and India.

International Mail Delivery

International Mail Delivery

Through our partnership with DHL, Pingen guarantees fast and reliable delivery to all other countries via air mail.

Scalable and reliable API

Scalable and Reliable

Pingen scales easily and is fail-safe due to our cloud and multi-site letter printing infrastructure.

Start Developing Now

Take a look at our Post API’s documentation and see how easy it is to integrate snail mail via Post and DHL into your software solution!