Azure Notification Hub REST API to get all registrations using paging with continuation token not working

Mark Hesketh 20 Reputation points
2025-09-17T08:11:53.07+00:00

Hi,

I'm using the GET all registrations API and there's a lot of registrations so i'm paging using the documented x-ms-continuationtoken but, I keep getting duplicates like it's not paging. The token doesn't change in the response on each request (not sure it does) but, the point is the results are the same for each page. Am I misusing this?

I have a script I can share:

!/usr/bin/env zsh

# ===== CONFIGURATION =====
NAMESPACE="your-namespace"              # e.g. myhubnamespace
HUB_NAME="your-hub"                     # e.g. myhub
API_VERSION="2016-07"                   # Notification Hubs REST API version
OUTPUT_FILE="registrations.xml"

# Use your pre-generated SAS token here (quoted to preserve spaces)
SAS_TOKEN='SharedAccessSignature sr=....&sig=....&se=....&skn=....'

# ===== BEGIN FETCH LOOP =====
URI="https://${NAMESPACE}.servicebus.windows.net/${HUB_NAME}/registrations?api-version=${API_VERSION}"

# Clear the output file
: > "$OUTPUT_FILE"

CONTINUATION=""
PAGE=1

while true; do
  echo "Fetching page $PAGE..."

  RESPONSE_HEADERS=$(mktemp)

  if [[ -n "$CONTINUATION" ]]; then
    RESPONSE=$(curl -sS -D "$RESPONSE_HEADERS" \
      -H "Authorization: $SAS_TOKEN" \
      -H "x-ms-continuationtoken: $CONTINUATION" \
      "$URI")
  else
    RESPONSE=$(curl -sS -D "$RESPONSE_HEADERS" \
      -H "Authorization: $SAS_TOKEN" \
      "$URI")
  fi

  # Append results
  print -- "$RESPONSE" >> "$OUTPUT_FILE"

  # Extract continuation token (case-insensitive, strip CR)
  CONTINUATION=$(grep -i "x-ms-continuationtoken:" "$RESPONSE_HEADERS" | awk '{print $2}' | tr -d '\r')

  rm "$RESPONSE_HEADERS"

  if [[ -z "$CONTINUATION" ]]; then
    echo "No more pages."
    break
  fi

  (( PAGE++ ))
done
Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
{count} votes

1 answer

Sort by: Most helpful
  1. Mark Hesketh 20 Reputation points
    2025-09-17T23:59:06.74+00:00

    Quick follow up - here's the dump of the response headers to confirm it's not changing in spite of the volume of data to page over:

    HTTP/2 200 
    content-type: application/xml
    date: Wed, 17 Sep 2025 23:55:35 GMT
    server: Kestrel
    strict-transport-security: max-age=2592000
    trackingid: 64f81596-d515-4bb9-a436-7f9c50652c9f
    x-ms-correlation-request-id: 83fc632e-9ecf-45e0-b3cc-6f07f7913295
    x-ms-continuationtoken: MTA7MTAwMA%3D%3D
    
    Fetching page 2...
    x-ms-continuationtoken = MTA7MTAwMA%3D%3D
    Response file: 
    
    HTTP/2 200 
    content-type: application/xml
    date: Wed, 17 Sep 2025 23:55:46 GMT
    server: Kestrel
    strict-transport-security: max-age=2592000
    trackingid: 21691654-6f87-4cc9-bd5a-bd5bb223fda1
    x-ms-correlation-request-id: 13c81e5d-c927-4c5e-b8a8-1c013ae97f96
    x-ms-continuationtoken: MTA7MTAwMA%3D%3D
    
    ✅ All registrations written to registrations.xml
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.