Notification Handler active only for 24 hours. Gives 400 after that

Hi,
I have created a NotificationHandler instance to listen to events from a topic. Normall for the first 24 hours everything works fine but communication channel gives "Client Not found" after 24 hours. Here is the error response json.

=====================================================
status: 400
body: {"error":"invalid_client","description":"client not found","error_description":"client not found"}

I understand that the channel is active only for 24 hours. But how do add logic into my code such that it remains active forever and i don't get any such errors. We are using Spring Configuration to authorize the api client and connect the NotificationHandler. Here is the sample code:

Setting up ApiClient

 @Bean
public ConversationsApi conversationsApi(ApiClient apiClient, NotificationHandler notificationHandler) {
    return new ConversationsApi(apiClient);
}

@Bean
public NotificationHandler notificationHandler(ApiClient apiClient, ChatNotificationListener chatNotificationListener) throws WebSocketException, IOException, ApiException {
    try {
       
        NotificationHandler handler = NotificationHandler.Builder.standard().withApiClient(apiClient).withNotificationListener(chatNotificationListener)
                .withAutoConnect(true).build();
        handler.connect(true);
        return handler;
    } catch (ApiException | WebSocketException | IOException e) {
        log.error("Exception when calling postNotificationsChannels", e);
        throw e;
    }
}

@Bean
public ApiClient apiClient(@Value("${genesys.auth.client.id}") String clientId, @Value("${genesys.auth.client.secret}") String clientSecret) throws IOException, ApiException {
    var apiClient = ApiClient.Builder.standard().withBasePath(PureCloudRegionHosts.ap_southeast_2)
            .withLoggingConfiguration(buildLoggingConfiguration())
            .withRetryConfiguration(buildRetryConfiguration()).build();
    apiClient.authorizeClientCredentials(clientId, clientSecret);
    apiClient.setShouldRefreshAccessToken(true);
    com.mypurecloud.sdk.v2.Configuration.setDefaultApiClient(apiClient);
    return apiClient;
}

private ApiClient.RetryConfiguration buildRetryConfiguration() {
    return new ApiClient.RetryConfiguration();
}

private ApiClient.LoggingConfiguration buildLoggingConfiguration() {
    var loggingConfiguration = new ApiClient.LoggingConfiguration();
    loggingConfiguration.setLogLevel("debug");
    loggingConfiguration.setLogRequestBody(true);
    loggingConfiguration.setLogResponseBody(true);
    return loggingConfiguration;
}

=======================================================

Hello,

A Notification Channel is active for 24 hours. To maintain a channel for longer than 24 hours, you have resubscribe to topics (before the channel expires - before 24 hours).
See the User the notification service page for more information on usage limitations.

In order to resubscribe to topics, you can easily do this with a POST /api/v2/notifications/channels/{channelId}/subscriptions- Java SDK: postNotificationsChannelSubscriptions with an empty array/list (as body).
The postNotificationsChannelSubscriptions with empty array will allow to resubscribe to all the topics of this channel (the ones you had subscribed to) and it will extend the Notification Channel for 24 hours again.

In your code, you will have to implement a recurring task/timer that will call this method (e.g. every 23 hours after the notification channel was created).

Also note that you will have to do something similar for your access token.
The refresh of access token is only supported when using an Authorization Code Grant.
As you are using a Client Credentials Grant (e.g. for a server side application - with no user context/credentials involved), you will also have to implement a recurring task/timer to request a new token before the current expires (with authorizeClientCredentials again).
The duration of the access token depends on what you have configured in your OAuth client. Set to 86400 (one day) by default.

Regards,

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