Subscribe

GET {{BASE_URL}}/topics/:cacheName/:topicName

Ready to subscribe to a topic using Momento’s long polling endpoint? Awesome! Let’s walk through what you need to do.

What to set up

You’ll need your access token, which we highly recommend doing with Qodex's easy auth. Just click on the address bar and hit that setup new authorization button. Qodex will do the rest.

Next up, you need to set the cacheName and topicName variables. You can configure these in the Variables tab of the collection or set them directly in the parameters of this request if you'd like. Remember, the cache needs to be in the same region as your API key. And the topic name? That’s totally up to you—Momento Topics are dynamic and are created on the fly, so feel free to get creative.

Optional parameters

There’s an optional sequence_number query parameter you can pass in if you want to ensure messages are delivered in the correct order or check for discontinuities. Handy, right?

What is long polling?

Once you fire off this request, the long polling kicks in. The server will keep the connection open until it has a message ready for you. No timeouts here. If you provided a sequence_number, it’ll resume from there. Otherwise, it starts from the latest available message.

Got your 200 OK? Nice! That means you successfully received a message. If there’s a gap in the sequence numbers, don’t worry—it will show up in the response so you know exactly what you're missing.

tl;dr - when you call this endpoint, it's going to wait to give you a response until a message is published on the topic.

Anything else?

That’s it! You’re now subscribed and receiving messages. You can head over to the Topics dashboard, plug in your region, cache, and topic, and hit the Publish button to validate that everything’s flowing smoothly.

If you have any questions or need help, swing by our Discord—we’re always happy to help!

Request Params

KeyDatatypeRequiredDescription
sequence_numberstringUsed to verify you haven't missed any messages. If the sequence number of the first message received in the response has a gap between this value, you will receive a discontinuity object in the response.