Marktplaats / 2dehands / 2ememain API solutions for Lead Management Systems

1 Introduction

This document is an overview of the different solutions we offer for lead management systems (LMSs), how they differ, and how they can be used together.

2 Vocabulary

3 Overview

We currently offer two different push-based services and one pull-based service:

3.1 Lead delivery webhook service

A push-based service that sends leads to your system. This includes:

3.2 LMS Bidirectional communication API

A (pull-based) chat API.

3.3 Chat message webhook service

An extension of the Bidirectional Communication API that will push new chat messages to your system, so you don’t need to poll the Bidirectional Communication API all the time.

3.4 Difference between the Lead Delivery Webhook and Chat Message Webhook.

Both of these services offer webhook functionality. But they have a different purpose, and for the best experience for your customers, we recommend you use both.

4 Implementation example

You can mix these different solutions however you wish, but here is an example flow that works best in our experience. This is assuming you have already subscribed your customer to all three services.

  1. Listen to the Lead Delivery Webhook, and process incoming leads. You can use our seller data fields to route it immediately to a specific sales agent.
  2. Call the Bidirectional Communication API GET conversation call to get the initial state of the conversation.
  3. Listen to new messages in the chat using the Chat Message Webhook.
  4. Use the Bidirectional Communication API to allow the seller to send replies, as well as mark conversations as read.

Step 2 may not be necessary, but this depends on your implementation. It deals with the theoretical situation where the buyer sends a second message before you had a chance to process their initial lead of step 1. All processing on our side is async, so we do not give guarantees on the specific order you will receive webhook messages in.

5 How to connect

If you have no existing connections to MP/TWH yet, please contact us to discuss the possibilities.

Once the paperwork is done, our technical team will supply you with all information you need to set up your API. After that, to actually connect users, we have the following processes in place:

We can give you access to our Sandbox environment for integration testing if necessary.

6 Forward compatibility

It’s essential to be aware of our forward compatibility philosophy regarding JSON payloads:

We can always add new properties to our payloads (even in patch version updates). This should not break your implementation. As this is not always the default behaviour for JSON deserialization frameworks (e.g. Jackson), please double-check that you can deserialize payloads that contain more properties than are stated in the specification.

7 Webhooks implementation details

7.1 Error responses and retries

Your webhook endpoint is required only to reply with one of the HTTP response codes mentioned in the OpenAPI specification.

Generally, we treat response codes as follows:

This means:

7.2 Request signatures

Our webhook requests contain a signature that allow you to verify both the identity and integrity of the request - that is, does the request actually come from us, and did you get the complete request without modifications? For more info see cavage http signatures.

If you look into a webhook request, you will find two relevant HTTP headers:

digest: SHA-256=46cf432d88fd959d5955031ce2fe34969409284ee51d4c38e19d3a96333c1454

signature: keyId="leadDeliveryKey",algorithm="RSA",created=1636631099,headers="(request-target) (created) digest",signature="27cb4ddfa2e1ef9b9179372b3a41429921249fa8c40cfc86d4b82a79c502f115eeb48d31d23c14bdfa2cfb59abe26ae30a1cbbe219e807b4599c987e2300936045c550cb434a79ccf74b1bd6f7e6829a2a215c339a35a112af79de47a2c37702b32d72a36596e02c741aadc4aa1f71d69bb7afbbaf3040786eb02a81657d5acb8207e8542667dd17898e5975a7e78257b1bec5b5337797923773683a7b600606f10fc5a87185cacd8653cc7bbd18509dfc86c66235360098ed79a4ff295e39d17219c121de86758b9e44b44e952a70189fb1f090c3addb0d76809ac24cdfec28aaab599d48e595cdc466447b00dad0ccd3d6db8aea9dc7c54eac1dd3021fc093

The digest is simply a SHA-256 digest of the message itself.

The signature http header is a very long header with different “sub-fields”:

Here is an example on how to manually verify the signature:

Step 1. Collect the signature data headers and combine them into a signature string:

echo "(request-target): post /webhook
(created): 1636631099
digest: SHA-256=46cf432d88fd959d5955031ce2fe34969409284ee51d4c38e19d3a96333c1454" > header.txt

IMPORTANT: The signature string contains a trailing new line. Make sure that the signature string you want to verify contains this trailing line feed (not \crlf).

Step 2. Convert the hex-encoded signature to binary:

echo "27cb4ddfa2e1ef9b9179372b3a41429921249fa8c40cfc86d4b82a79c502f115eeb48d31d23c14bdfa2cfb59abe26ae30a1cbbe219e807b4599c987e2300936045c550cb434a79ccf74b1bd6f7e6829a2a215c339a35a112af79de47a2c37702b32d72a36596e02c741aadc4aa1f71d69bb7afbbaf3040786eb02a81657d5acb8207e8542667dd17898e5975a7e78257b1bec5b5337797923773683a7b600606f10fc5a87185cacd8653cc7bbd18509dfc86c66235360098ed79a4ff295e39d17219c121de86758b9e44b44e952a70189fb1f090c3addb0d76809ac24cdfec28aaab599d48e595cdc466447b00dad0ccd3d6db8aea9dc7c54eac1dd3021fc093" > signature.txt

xxd -r -p signature.txt signature.sha256

Step 3. Verify the signature and integrity of data headers against the public key.

openssl dgst -sha256 -verify key.pub -signature signature.sha256 header.txt

The output of this command should be:

Verified OK

Please ask your technical contact at Marktplaats/2dehands for a copy of the relevant public keys.

8 API docs