Skip to main content

    Build foundational API knowledge

    Course overview
    Lesson
    4 min read

    Try it: Make a POST request

    Follow along with these interactive exercises to create custom events using POST requests.

    Format and send POST requests

    Now, it's your turn. Recall that Beantown is expanding into coffee seminars, and they need to customize their setup accordingly. We will use Postman to complete the following series of exercises:

    • Creating a Booked seminar event
    • Updating a custom profile property
    • Adding profiles to the Seminar attendees list

    Feel free to refer to the following resources as you work through these exercises:

    Create an event

    Use the Create Event endpoint to create an event called Booked seminar in your test account. Every event is associated with a certain profile, representing the person who did that event, in this case, the person who booked the seminar. You can use any email address to represent the profile who booked the seminar.

    The Booked seminar event should include the following information:

    • Seminar name
    • Seminar date
    • Location

    Make sure the date is formatted in one of the accepted date and timestamp formats.

    Update a profile property

    Beantown also wants to set up a date-triggered flow based on the seminar date. To do so, they need to add the seminar date as a profile property. The name of this property should be Seminar date, and the value should be the date you sent over in the Booked seminar event.

    Use the Update Profile endpoint to add a custom profile property to the profile you used for the Booked seminar event.

    Again, make sure the date is formatted in one of the accepted date and timestamp formats.

    Note that you will need to get this profile's ID in order to use the Update Profile endpoint. You can do so by navigating to the profile in Klaviyo and copying the alphanumeric ID from the URL:

    getting profile ID from the URL of a Klaviyo profile

    As an advanced challenge, you can also try getting the profile ID using the Get Profiles API endpoint with the email filter.

    Select the correct list endpoint

    In the first exercise in this course, you created a list called Seminar attendees. Now, let's use APIs to add the profile who Booked seminar to this list.

    There are 2 endpoints that can add profiles to a list:

    Read the description of each endpoint.

    Which endpoint should you use here, and why?

    Add the profile to the list

    Once you have selected the correct endpoint, use Postman with this endpoint to add the profile to the list.

    You can confirm that the profile was added correctly by navigating to the list and ensuring the profile was added.

    Solutions

    Create an event

    The request body should look like:

    You can confirm the event went through successfully by navigating to the Klaviyo profile associated with the email address you used in the API call and making sure the event shows up on the activity log:

    Update a profile property

    The first step is to get the profile ID. You can either find this by copying the alphanumeric ID from the URL associated with the profile in Klaviyo:

    Alternatively, click on the Get Profiles endpoint in Postman and add equals(email,"michaela.klaviyo@gmail.com") as a filter, replacing michaela.klaviyo@gmail.com with the email address of the profile you are working with.

    The response body will contain the profile ID.

    Once you have the profile ID, click on the Update Profile endpoint in Postman. In the Params tab, add the profile ID as the value associated with id under Path Variables.

    The body should look like:

    text
    {
       "data": {
          "type": "profile",
          "id": "01G9ATZKKMSZMDB76EN6WVMVGM",
          "attributes": {
              "properties": {
                  "Seminar date": "2024-07-04"
              }
          }
       }
    }

    Replacing 01G9ATZKKMSZMDB76EN6WVMVGM with your profile ID.

    __wf_reserved_inherit

    You can confirm the profile property was updated correctly by confirming that it shows up under Custom properties on the Klaviyo profile:

    Select the correct list endpoint

    The Add Profile to List endpoint adds a profile to a list without affecting its subscription status, while the Subscribe Profiles endpoint subscribes profiles to marketing while adding them to the list.

    In this example, we do not have any information on whether profiles have provided consent to marketing. We only want to add them to a list without subscribing them to marketing. Therefore, the correct endpoint is Add Profile to List. It is generally best practice to only subscribe customers who have explicitly given consent to marketing. You can read more about consent here.

    Add the profile to the list

    In Postman, click on the Add Profile to List endpoint. Under the Body tab, add the profile ID. The body should look like:

    text
    {
        "data": [
            {
                "type": "profile",
                "id": "01G9ATZKKMSZMDB76EN6WVMVGM"
            }
        ]
    }

    Then, under the Params tab, add the ID of the Seminar attendees list as the value associated with the id Path Variable:

    __wf_reserved_inherit

    You can then navigate to the list in Klaviyo to confirm the profile was added to the list:

    Try it: Make a POST request