Skip to content
Example: one partner, both directions

Example: one partner, both directions

This page walks through a complete AS2 setup for one partner. Your organization mycompany sends files to the partner acme and receives files from it.

What you need

  • MicroB2B installed and running. See Install.
  • Your certificate with its private key, and ACME’s public certificate.
  • From ACME: their AS2 ID (ACME) and their endpoint (https://as2.acme.example/as2).
  • The organization mycompany and the partner acme, created under Organizations and Partners.

Agree with ACME on your AS2 ID (MYCOMPANY) and the URL of your receiver.

In the web UI

  1. Certificates. Under Certificates > + Upload Certificate, upload your certificate with its key, and ACME’s certificate. See Certificates.
  2. Your AS2 profile. Open Organizations > mycompany and choose Configure AS2. Enter AS2 ID MYCOMPANY, choose your certificate as Our Certificate, and enter MDN Notification To, for example [email protected]. Save.
  3. ACME’s AS2 profile. Open Partners > acme and choose Configure AS2. Enter AS2 ID ACME, the endpoint https://as2.acme.example/as2, and choose ACME’s certificate as Partner Certificate. Keep the other defaults: they sign, encrypt and ask for a signed receipt. Save.
  4. Receiver and sender. A fresh installation has as2_receiver_default (port 8081, path /as2) and as2_sender_default. Check them under Plugins > AS2 Receivers and Plugins > AS2 Senders.
  5. Files. A fresh installation has file_poller_default, which reads data/outbox, and file_writer_default, which writes to data/inbox. The poller reads the partner from the folder name, so files in data/outbox/acme/ go to ACME. The writer puts received files in a folder per partner, such as data/inbox/acme/. The poller sends from your only organization. If you have more than one, set From (Organization) on the poller. See File poller.
  6. Routes. A fresh installation routes the default file poller to the default AS2 sender, and the default AS2 receiver to the default file writer. Check them under Routes. See Routes.
  7. Test. Open Partners > acme, choose Test Connection, then Check connection. When it passes, use Send test message. See Testing a partner.

Give ACME your public certificate and your receiver URL, for example https://as2.mycompany.example/as2. ACME sends with AS2-To: MYCOMPANY.

With the REST API

The same setup with new instances, as a script. It assumes that certificate 1 is yours (with its key) and certificate 2 is ACME’s. It also assumes that the organization and the partner both have ID 1. ACCESS_TOKEN is an API token; see Service accounts.

API=https://microb2b.example.com/api/v1
AUTH="Authorization: Bearer $ACCESS_TOKEN"
JSON="Content-Type: application/json"

curl -X POST -H "$AUTH" -H "$JSON" $API/as2/local-profiles -d '{
  "local_organization_id": 1, "as2id": "MYCOMPANY",
  "certificate_id": 1,
  "mdn_notification_to": "[email protected]"}'

# Secure defaults; only the identity, endpoint and certificate are needed
curl -X POST -H "$AUTH" -H "$JSON" $API/as2/remote-profiles -d '{
  "business_partner_id": 1, "as2id": "ACME",
  "endpoint": "https://as2.acme.example/as2", "partner_certificate_id": 2}'

curl -X POST -H "$AUTH" -H "$JSON" "$API/plugins/configs?type=as2-receiver" -d '{
  "name": "receiver_main", "port": "4080"}'
curl -X POST -H "$AUTH" -H "$JSON" "$API/plugins/configs?type=as2-sender" -d '{
  "name": "sender_main"}'
curl -X POST -H "$AUTH" -H "$JSON" "$API/plugins/configs?type=file-poller" -d '{
  "name": "outbox", "base_directory": "/data/outbox", "processed_directory": "/data/processed"}'
curl -X POST -H "$AUTH" -H "$JSON" "$API/plugins/configs?type=file-writer" -d '{
  "name": "inbox", "base_directory": "/data/inbox",
  "filename_pattern": "{from}/{original_filename|message_id}"}'

# Outgoing: files in /data/outbox/acme/ go to ACME. Incoming: everything ACME sends is written.
curl -X POST -H "$AUTH" -H "$JSON" $API/routes -d '{
  "source_plugin": "outbox", "from": "mycompany", "to": "acme", "target_plugin": "sender_main"}'
curl -X POST -H "$AUTH" -H "$JSON" $API/routes -d '{
  "source_plugin": "receiver_main", "from": "acme", "to": "*", "target_plugin": "inbox"}'

New instances start when MicroB2B restarts, or when you start them under System > Services. ACME then posts to http://<host>:4080/as2 with AS2-To: MYCOMPANY. Put a reverse proxy with HTTPS in front, or turn on HTTPS on the receiver. See AS2 receiver.

Check that it works

  • Put a file in the outbox folder for ACME. It appears under Messages and becomes Delivered once ACME’s receipt arrives.
  • Ask ACME to send a file. It appears under Messages and is written to the inbox folder.

If a message fails, open its page for the reason, and see AS2: sending problems.