New Feature: API Message Access

api-shared-urlNewly added to the Profile page is the ability to enable or disable API access to your messages.  When enabled a shared access URL is generated to be used with the Azure Blob Storage REST API.  The shared access URL allows listing files and reading of messages.  The URL can be used to access your messages from other software or for a one time download.

You can find examples of using the REST API HERE.

Here is an example of using the .NET Storage Client

/// <summary>
/// List your messages using .NET storage client library.
/// </summary>
/// <param name=” sharedAccessUrl “></param>
public void ListMessagesWithStorageClientLibrary(string sharedAccessUrl)
{
     CloudBlobContainer blobContainer = new CloudBlobContainer(new Uri(sharedAccessUrl));
     var blobs = blobContainer.ListBlobs(null, true);
     foreach (var blob in blobs)
     {
          Console.WriteLine(blob.Uri);
     }
}

Here is an example using the REST API to list your messages written in C#

/// <summary>
/// List messages in your container using REST API.
/// </summary>
/// <param name=” sharedAccessUrl “></param>
public void ListMessagesWithRestAPI(string sharedAccessUrl)
{
     string requestUri = string.Format(CultureInfo.InvariantCulture, “{0}&comp=list”, sharedAccessUrl);
     HttpWebRequest request = (HttpWebRequest) WebRequest.Create(requestUri);
     request.Method = “GET”;

     using (HttpWebResponse resp = (HttpWebResponse) request.GetResponse())
     {
          using (Stream s = resp.GetResponseStream())
          {
               using (StreamReader reader = new StreamReader(s, true))
               {
                    string messageData = reader.ReadToEnd();
                    Console.WriteLine(messageData);
               }
          }
     }
}

There is a great blog post on working with the shared access URL’s here.

Here are more resources on working with Azure Blob Storage using Ruby, Python, Java, PHP, Node.js and .NET

Comments are closed.