Creating your first conversation

1. Create your first patient

Use the Create a Patient endpoint.

Request (replace with you Server API token)

curl --request POST \
     --url https://api.nabla.com/v1/server/patients \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer <YOUR_TOKEN>' \
     --header 'Content-Type: application/json' \
     --data '
{
     "first_name": "Jane",
     "last_name": "Doe",
     "locale": "fr",
     "email": "[email protected]",
     "phone": "33612356789",
     "date_of_birth": "1972-06-23",
     "sex": "FEMALE"
}
'

Response

{
    "id": "6273169a-52ba-42af-a582-09ab8da1509e",
    "username": null,
    "first_name": "Jane",
    "last_name": "Doe",
    "locale": "fr",
    "email": "[email protected]",
    "phone": "33612356789",
    "sex": "FEMALE",
    "updated_at": "2022-06-15T13:37:39.034Z",
    "created_at": "2022-06-15T13:37:39.034Z"
}

Check to see her in the Console\Patients

imageimage

2. Create a conversation with this patient

Now create a conversation using /conversations endpoint and the patient id you received in step 1

Request (replace with you Server API token)

curl --request POST \
     --url https://api.nabla.com/v1/server/conversations \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer <YOUR_TOKEN>' \
     --header 'Content-Type: application/json' \
     --data '
{
     "patient_id": "6273169a-52ba-42af-a582-09ab8da1509e"
}
'

Response

{
    "id": "1248898b-5786-4320-9688-d3c744432020",
    "title": null,
    "patient": {
        "id": "6273169a-52ba-42af-a582-09ab8da1509e",
        "username": null,
        "first_name": "Jane",
        "last_name": "Doe",
        "locale": "fr",
        "email": "[email protected]",
        "phone": "33612356789",
        "sex": "FEMALE",
        "updated_at": "2022-06-15T13:37:39.034Z",
        "created_at": "2022-06-15T13:37:39.034Z"
    },
    "providers": [
    ],
    "tags": [
    ],
    "console_url": "https://titi.pro.nabla.com/inbox/unassigned/1248898b-5786-4320-9688-d3c744432020",
    "unread_patient_messages_count": 0
}

Check the Console's Conversations tab to see the new conversation!

imageimage

3. [Optional] Configure auto-reply in the Console

Go to the Settings part in the Console to set up auto-replies. You should see something like this:

imageimage

4. Send a first message

Use the /messages endpoint, the patient id and the conversation id to send a message on behalf of the patient

Request (replace with you Server API token)

curl --request POST \
     --url https://api.nabla.com/v1/server/messages \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer <YOUR_TOKEN>' \
     --header 'Content-Type: application/json' \
     --data '
{
     "author": {
          "type": "patient",
          "id": "6273169a-52ba-42af-a582-09ab8da1509e"
     },
     "conversation_id": "98FCE1EF-DBCA-41EF-8BC7-4D1621AC07C6",
     "text": "Hello, how are you?"
}
'

Response

{
    "id": "afe5c435-ba89-40df-b4b2-cdcf20538e58",
    "author": {
        "type": "patient",
        "id": "6273169a-52ba-42af-a582-09ab8da1509e",
        "username": null,
        "first_name": Jane,
        "last_name": Doe,
        "locale": "fr",
        "email": "[email protected]",
        "phone": "33612356789",
        "sex": "FEMALE",
        "updated_at": "2022-06-15T13:37:39.034Z",
        "created_at": "2022-06-15T13:37:39.034Z"
    },
    "text": "Hello, how are you?",
    "attachment": null,
    "created_at": "2022-06-16T06:35:45.934Z",
    "conversation_id": "1248898b-5786-4320-9688-d3c744432020"
}

You can see the message your Console's Conversations tab. If you did Step 3, you can also notice the auto reply.

5. Retrieve all the message from this conversation including the auto reply

Use now the /messages endpoint and the conversation id to retrieve the list of messages.

Request (replace with you Server API token)

curl --request GET \
     --url 'https://api.nabla.com/v1/server/messages?conversation_id=1248898b-5786-4320-9688-d3c744432020&metadata=' \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer <YOUR_TOKEN>'

Response

{
    "data": [
        {
            "id": "4474dadf-35fd-48b8-98de-c1e74f8b9ffe",
            "author": null,
            "author_type": "system",
            "text": "Hello back, we are outside of service hours!!!",
            "attachment": null,
            "created_at": "2022-06-16T06:35:46.259Z",
            "conversation_id": "1248898b-5786-4320-9688-d3c744432020"
        },
        {
            "id": "afe5c435-ba89-40df-b4b2-cdcf20538e58",
            "author": {
                "type": "patient",
                "id": "6273169a-52ba-42af-a582-09ab8da1509e",
                "username": null,
                "first_name": Jane,
                "last_name": Doe,
                "locale": "fr",
                "email": "[email protected]",
                "phone": "33612356789",
                "sex": "FEMALE",
                "updated_at": "2022-06-15T13:37:39.034Z",
                "created_at": "2022-06-15T13:37:39.034Z"
            },
            "text": "Hello, how are you?",
            "attachment": null,
            "created_at": "2022-06-16T06:35:45.934Z",
            "conversation_id": "1248898b-5786-4320-9688-d3c744432020"
        }
    ],
    "has_more": false,
    "total_count": 2,
    "next_cursor": "100"
}

6. Add an attachment and send it as a message from the patient

Add an attachement as a patient with the /attachments endpoint and the patient id.

Request (replace with you Server API token)

curl -X POST 'https://api.preprod.nabla.com/v1/server/attachments' \
 -H "Authorization: Bearer <YOUR_TOKEN>" \
 -F [email protected] \
 --form 'author={"id": "6273169a-52ba-42af-a582-09ab8da1509e", "type": "patient"};type=application/json' -v

Response

{
    "id": "06ac8ca3-cc07-4000-942b-0a775c395c8c",
    "ephemeral_url": {
        "url": "https://storage.googleapis.com/236d1010-e3ed-6deb-a563-de15b16dbf5d-attachment/73d42260-1b1d-4824-9a1f-46d8ccabdd09?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=health-back-app%40nabla-preprod.iam.gserviceaccount.com%2F20220616%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220616T083301Z&X-Goog-Expires=7200&X-Goog-SignedHeaders=host&X-Goog-Signature=81ac0d061cfd97379e032434f8125c79bf1a92abdb2539ff3eb7657a9bae3658bfe47f6e6f011ac634f7e0fdfaecc4c29e7d2b872ae9d510e6b1fbe78a198a1ae4ebf1c46a08eb8e956136aa1ae748c53c93941acf728e6ce919dd2fb7bfaf8bf7d776e7e71fc5e448b0c441cdfdc645d906984540d30e6e68b454f4f75ff66f45b5a99d40ca079b8c0fda00a1f836d6b9678b8cf69a7e12fc2b5955259c773ce17a577553860ea649e0759bfb44d2c9a199db23461b517b91e6959573ba69db1a5384ae797215b852f62297bcc54cfc71ebf667c6ac60ec60b3f141a2f5b0ca6ca5194567c579142cf5604a594fde5d573e78c5cbee1e637f097bfc9c8b223a",
        "expires_at": "2022-06-16T10:33:01.446Z"
    },
    "mime_type": "application/pdf",
    "thumbnail_url": {
        "url": "https://storage.googleapis.com/236d1010-e3ed-6deb-a563-de15b16dbf5d-attachment/c64ffe17-5ba1-4194-9e24-60836190fe3d?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=health-back-app%40nabla-preprod.iam.gserviceaccount.com%2F20220616%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220616T083301Z&X-Goog-Expires=7200&X-Goog-SignedHeaders=host&X-Goog-Signature=44ba1253be203583bec4a4c7aee11e5269818a77194b121226a3ab3b74999e1878bf10fd5be0b2cea2dad47b2cc011524769f663b9aeebdc7c862707fe22ca0a538babd548c625df7d961fffa05c5b9ba4050160ceea1db6b35149223bde0389ccf263e34fba85c62eb01eb78fe8ca802dc1d0186de7a014e34d6579fd3776dd7e66e2cea2d18ecadcb5267c5514f6c41e5187433824c915327efd342b57cca1b57e0d7486d0f67485aa7a51e401d611dac877d500caa5e6030bd19bb83ac26996b83e1b9a52c0345d3be32523a4b09b0143f4f47ecbde13bd5b497cf2c6de1bdebdbac4da96fee700b59dd3ada779e2f65279d2b3d7255d18f4feb94cc866c9",
        "expires_at": "2022-06-16T10:33:01.483Z"
    },
    "author": {
        "type": "patient",
        "id": "6273169a-52ba-42af-a582-09ab8da1509e",
        "username": null,
        "first_name": Jane,
        "last_name": Doe,
        "locale": "fr",
        "email": "[email protected]",
        "phone": "33612356789",
        "sex": "FEMALE",
        "updated_at": "2022-06-15T13:37:39.034Z",
        "created_at": "2022-06-15T13:37:39.034Z"
    },
    "created_at": "2022-06-16T08:33:00.636Z"
}

Now send a message with the /messages endpoint attachment id and the patient id

Request (replace with you Server API token)

curl --request POST \
     --url https://api.nabla.com/v1/server/messages \
     --header 'Accept: application/json' \
     --header 'Authorization: Bearer <YOUR_TOKEN>' \
     --header 'Content-Type: application/json' \
     --data '
{
     "author": {
          "type": "patient",
          "id": "6273169a-52ba-42af-a582-09ab8da1509e"
     },
     "attachment": {
          "payload": {
               "file_upload_id": "06ac8ca3-cc07-4000-942b-0a775c395c8c"
          }
     },
     "conversation_id": "1248898b-5786-4320-9688-d3c744432020"
}
'

Response

{
    "id": "f6b203f8-07ee-4201-917f-f9884758a122",
     "author": {
        "type": "patient",
        "id": "6273169a-52ba-42af-a582-09ab8da1509e",
        "username": null,
        "first_name": Jane,
        "last_name": Doe,
        "locale": "fr",
        "email": "[email protected]",
        "phone": "33612356789",
        "sex": "FEMALE",
        "updated_at": "2022-06-15T13:37:39.034Z",
        "created_at": "2022-06-15T13:37:39.034Z"
    },
    "text": null,
    "attachment": {
        "id": "06ac8ca3-cc07-4000-942b-0a775c395c8c",
        "ephemeral_url": {
            "url": "https://storage.googleapis.com/236d1010-e3ed-6deb-a563-de15b16dbf5d-attachment/73d42260-1b1d-4824-9a1f-46d8ccabdd09?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=health-back-app%40nabla-preprod.iam.gserviceaccount.com%2F20220616%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220616T130322Z&X-Goog-Expires=7200&X-Goog-SignedHeaders=host&X-Goog-Signature=17301202c845daf854b8e1a6d658e36edfa64897d5a944015e44f21f521da97ad5cef68d05a776ee85a263477c845c9e62fbd6fe80b61da232a42b9e1f8326ef647961a892a9acfabae8e3758e109028c79d9e895430de7fb33d0ecb6da0d46531eb4396927b5264e854246c38e1c5436babc550c78fc6cb5184b1f6a1b09fca9ef91e48ee35221babaa99c4a4a761ec2b14729ccd29d5cd89370c00381c12a960fcdda06802bb14a246477a54b65d6d91acb586ae4e6ea55f764c09c2259bb8dd45f8f5b592a94178b83c01cb514bbfa43beed4e14179bbabd60d193a67ecb467f9c16498cbd2efbfef5bcf6e874f5a9ff0ea1d21a38ff5eaffef2dc91b0896",
            "expires_at": "2022-06-16T15:03:22.388Z"
        },
        "mime_type": "application/pdf",
        "thumbnail_url": {
            "url": "https://storage.googleapis.com/236d1010-e3ed-6deb-a563-de15b16dbf5d-attachment/c64ffe17-5ba1-4194-9e24-60836190fe3d?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=health-back-app%40nabla-preprod.iam.gserviceaccount.com%2F20220616%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220616T130322Z&X-Goog-Expires=7200&X-Goog-SignedHeaders=host&X-Goog-Signature=0532b3ef6bd738d2641698e939806813371bf11be1bb22208a8b2710ec092ab102849d6789792eb31472e2713fb9c26d3856bfff26c5f4815c46e92d32c937eab7323b4e1b2a208177f43d0cc1bc1b9ce2915c42a4fb5a3aff5dd0a48496f98b673a62db67a9edb92747daffc5be68a89bc2f2d12390f6658bded6c76aeca8ac39a5c5ca356e395fe2caa41fae5285ea3a089c87466b9ffb3b1a4e3dcd5e25b472e329c95f3d2dca88481b36657b682c658fe85f63224d6e14e29725cf07e7a4677e9bca8be097655bdabdc8a00b29ee7a641f4f7cc4f486d7cc0399295e571dd2e040295b7a0115743d13266f976b157dd464748dcc862be42a434f8ccd5903",
            "expires_at": "2022-06-16T15:03:22.419Z"
        }
    },
    "created_at": "2022-06-16T13:03:22.212Z",
    "conversation_id": "1248898b-5786-4320-9688-d3c744432020",
    "metadata": null
}

Check in the Console that you see the file in the conversation.

imageimage