Notifications API subscribe to topics request body

Good afternoon,

I'm using python to subscribe to topics using the requests library (not the platform client SDK). I've tried to create the request body a number of different ways. I've tried data=data and json=data. I'm trying to subscribe to multiple topics at once. What is the right way?

Here is my latest attempt. I keep getting a 400 Bad request no matter what I do.

        data = json.dumps({
            "type": "subscribe",
            "topics": topics,
            "id": str(uuid.uuid4())
        })

        print(data, type(data))

        uri = gencloud_auth[self.org_id]["api_uri"]
        self.headers = {
            "Authorization": f"{gencloud_auth[self.org_id]['token_type']} {gencloud_auth[self.org_id]['access_token']}",
            "Content-Type": "application/json"
        }

        endpoint = f"/api/v2/notifications/channels/{self.channel_id}/subscriptions"
        sub_uri = f"{uri}{endpoint}"
        response = requests.put(sub_uri, headers=self.headers, json=data)
        print(response)

        if response.status_code >= 400:
            print(response.text)
            raise Exception(f"Error subscribing: {response.text}")

You'll need to construct a request body in accordance with the documentation; your data object bears no resemblance to the endpoint's documented payload: PUT /api/v2/notifications/channels/{channelId}/subscriptions. See this guide for an overview of how to use notifications: https://developer.genesys.cloud/notificationsalerts/notifications/.

You may also wish to use the Python SDK: https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudpython/NotificationsApi#put_notifications_channel_subscriptions

Thank you Tim - I realized it was expecting an array within a few moments of posting this. For whatever reason I kept overlooking the "array of" in the Schema documetation.

Thanks, Dan

It's not just the array, all the properties are wrong. Type and topics aren't properties in the object. id is the only one you need to set and it's not an arbitrary value and it's not a GUID; it's a topic from the list of available topics.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.