Monday, January 11, 2016

Azure Notification Hub "Tags" Cannot Contain Spaces

A quick word on Azure Notification Hub "Tags".

"Tags" cannot contain spaces. This isn't covered/obvious is most of the samples/tutorials. They don't use spaces and don't discuss restrictions on the tag content.

The only documentation I've found so far on allowed characters is this;

Before I found this I spent some time trying to figure out why my push notifications weren't working. It appears the Microsoft.Azure.NotificationHub packages doesn't report errors with invalid tags when registering them.

Calling methods such as CreateMpnsTemplateRegistrationAsync with an invalid tag will not throw an exception. The result object will appear correct, with a valid registration id. The only hint of a problem (apart from it not working) is the tags collection on the result will be empty. If more than one tag is supplied but only some are invalid, none register.

SendTemplateNotificationAsync does throw an exception if you send to an invalid tag. 

In my case I was sending to a valid tag, but it was not registered because one of the other tags was invalid during registration. It took me a while to figure it out since the registration looked like it was working and the send was successful but no notification arrived.

The lack of spaces is pretty sad given my requirements (many of my tags come from user configuration). What is most annoying though is the lack of validation/error reporting on registration. An exception with a good error message would have saved me a lot of time. Hopefully this note saves someone else the time I wasted.

No comments:

Post a Comment