Webhooks

In this guide, we will look at how to register and consume webhooks to integrate your app with Avon. With webhooks, your app can know when something happens in Avon, such as someone sending a message or adding a patient.

Registering webhooks

To register a new webhook, you'll need to send your Avon contact an endpoint that Avon can call when an event happens. Also let your Avon contact know which of the event types you want to listen for.

Now, whenever something of interest happens in the EMR or patient portal, a webhook is fired off by Avon. In the next section, we'll look at how to consume webhooks.

Consuming webhooks

When your app receives a webhook request from Avon, check the event attribute to see what event caused it. The first part of the event type will tell you the payload type, e.g., a conversation, message, etc.

Example webhook payload

{
  "event": "patient.created",
  "created_at": "2024-02-22T20:09:46.206Z",
  "object": {
    "id": "user_Z1zXZKvqrpwxbznuW6lJ"
    // ...
  }
}

In the example above, a patient was created, and the object type is a patient.


Event types

  • Name
    patient.created
    Type
    Description

    A new patient was created.

  • Name
    patient.updated
    Type
    Description

    A patient was updated.

  • Name
    provider.created
    Type
    Description

    A new provider was created.

  • Name
    provider.updated
    Type
    Description

    A provider was updated.

  • Name
    support.created
    Type
    Description

    A new support member was created.

  • Name
    support.updated
    Type
    Description

    A support member was updated.

  • Name
    appointment.created
    Type
    Description

    A new appointment was created.

  • Name
    care_team.updated
    Type
    Description

    A care team was updated.

  • Name
    appointment.created
    Type
    Description

    A new appointment was created.

  • Name
    appointment.completed
    Type
    Description

    An appointment was completed.

  • Name
    appointment.cancelled
    Type
    Description

    An appointment was cancelled.

  • Name
    appointment.rescheduled
    Type
    Description

    An appointment was rescheduled.

  • Name
    appointment.started
    Type
    Description

    An appointment was started.

  • Name
    appointment.updated
    Type
    Description

    An appointment was updated.

  • Name
    appointment.deleted
    Type
    Description

    An appointment was deleted.

  • Name
    document.created
    Type
    Description

    A document was created.

  • Name
    document.updated
    Type
    Description

    A document was updated.

  • Name
    document.deleted
    Type
    Description

    A document was deleted.

  • Name
    lab_result.created
    Type
    Description

    A new lab result was created.

  • Name
    task.created
    Type
    Description

    A new task was created.

  • Name
    task.updated
    Type
    Description

    A task was updated.

  • Name
    task.deleted
    Type
    Description

    A task was deleted.

  • Name
    message.created
    Type
    Description

    A new message was created.

  • Name
    message.updated
    Type
    Description

    A message was updated.

  • Name
    message.deleted
    Type
    Description

    A message was deleted.

  • Name
    message_thread.created
    Type
    Description

    A new message thread was created.

  • Name
    message_thread.updated
    Type
    Description

    A message thread was updated.

  • Name
    note.created
    Type
    Description

    A new note was created.

  • Name
    note.updated
    Type
    Description

    A note was updated.

  • Name
    note_answer.updated
    Type
    Description

    A note answer was updated.

  • Name
    note_answer.updated
    Type
    Description

    A note answer was updated.

  • Name
    allergy.created
    Type
    Description

    A new allergy was created.

  • Name
    allergy.updated
    Type
    Description

    An allergy was updated.

  • Name
    allergy.deleted
    Type
    Description

    An allergy was deleted.

  • Name
    condition.created
    Type
    Description

    A new condition was created.

  • Name
    condition.updated
    Type
    Description

    A condition was updated.

  • Name
    condition.deleted
    Type
    Description

    A condition was deleted.

  • Name
    family_history.created
    Type
    Description

    A new family history record was created.

  • Name
    family_history.updated
    Type
    Description

    A family_history record was updated.

  • Name
    condition.deleted
    Type
    Description

    A family_history record was deleted.

  • Name
    medication.created
    Type
    Description

    A new medication was created.

  • Name
    medication.updated
    Type
    Description

    A medication was updated.

  • Name
    medication.deleted
    Type
    Description

    A medication was deleted.

  • Name
    vitals.created
    Type
    Description

    A new vitals record was created.

  • Name
    vitals.updated
    Type
    Description

    A vitals record was updated.

  • Name
    vitals.deleted
    Type
    Description

    A vitals record was deleted.

Example payload

{
  "event": "patient.created",
  "created_at": "2024-02-22T20:09:46.206Z",
  "object": {
    "id": "user_Z1zXZKvqrpwxbznuW6lJ",
    "object": "patient",
    "mrn": "8942726",
    "first_name": "Sally",
    "middle_name": "",
    "last_name": "Chen",
    "gender": "Female",
    "email": "sally@demo.com",
    "phone": "(408)872-5892",
    "date_of_birth": "1990-02-22",
    "ssn": "765876575",
    "caregiver": "user_X90XZKvqrpwxbznuW6lJ",
    "caregiver_only": false,
    "medical_centers": [
        "mctr_XbvBirnEb1Mli1OLwqnM"
    ],
    "addresses": [{
        "nickname": "Home",
        "line1": "60 W Main St",
        "city": "Avon",
        "state": "CT",
        "postal_code": "06001",
        "country": "US",
        "special_instructions": "Has a loud dog"
    }],
    "timezone": "America/New_York",
    "status_history": [
        {
            "status": "active",
            "changed_by": "user_Z1zXZKvqrpwxbznuW6lJ",
            "changed_at": 1653798303000
        }
    ],
    "custom_data": [{
        "key": "cfld_FZR6ioEDTkHKn62oknLF",
        "value": "Routine Care"
    }],
    "created_by": "user_Z1zXZKvqrpwxbznuW6lJ",
    "created_at": "2024-02-22T20:09:46.206Z",
    "last_updated_at": "2024-02-22T20:09:46.206Z"
  }
}

Security

To know for sure that a webhook was, in fact, sent by Avon instead of a malicious actor, you can verify the request signature. Each webhook request contains a header named avon-signature, and you can verify this signature by using your secret webhook key. The signature is an HMAC hash of the request payload hashed using your secret key. Here is an example of how to verify the signature in your app:

Verifying a request

const signature = req.headers['avon-signature']
const hash = crypto.createHmac('sha256', {{webhook_secret_key}}).update(payload).digest('hex')

if (hash === signature) {
  // Request is verified
} else {
  // Request could not be verified
}

If your generated signature matches the avon-signature header, you can be sure that the request was truly coming from Avon. It's essential to keep your secret webhook key safe — otherwise, you can no longer be sure that a given webhook was sent by Avon. Don't commit your secret webhook key to GitHub!