API Extensions and Subscriptions
Learn about recent changes to API Extensions and Subscriptions, and how to apply them using the TypeScript or Java SDK.
After completing this page, you should be able to:
- Identify how the changes affect the TypeScript and Java SDKs.
- Apply the updated features using the TypeScript or Java SDK.
API Extensions and Subscriptions are game-changers, transforming the way you interact with your digital commerce operations. Imagine customizing Composable Commerce to fit your business like a glove.
With API Extensions, you can inject your unique business logic directly into the API's workflow. This means you can perform real-time validations, modify shopping carts with custom rules, or even calculate bespoke shipping costs on the fly. Subscriptions let you have web hook messages delivered straight to your message queue.
Both API Extensions and Subscriptions have received a number of significant updates over the last year. CloudEventsFormat—a feature introduced in beta in 2022—became generally available in 2023, ensuring consistency when using CloudEvents across different message queues. That's not all!
We also introduced two more new destinations: Confluent Cloud for Subscriptions and Google Cloud Functions for API Extensions.
The following example shows how you can set up a new Subscription with Confluent Cloud as its destination and CloudEventsFormat as its delivery format. The message is sent whenever a Product gets published.
For the subscription to be created, you need to use a valid Confluent Cloud Queue.
import { apiRoot } from '../impl/apiClient.js'; // Update to map to your API rootasync function createSubscription() {try {const response = await apiRoot.subscriptions().post({body: {destination: {key: 'my_kafka_record_key',type: 'ConfluentCloud',bootstrapServer: '[cluster-id].<region>.gcp.confluent.cloud:port',apiKey: 'xxx',apiSecret: 'xx',acks: 'all',topic: 'my_topic',},format: {type: 'CloudEvents',cloudEventsVersion: '1.0',},messages: [{resourceTypeId: 'product',types: ['ProductPublished'],},],},}).execute();console.log('Success', JSON.stringify(response.body, null, 2));} catch (error) {console.log(JSON.stringify(error, null, 2));}}createSubscription();