Skip to content
AnnA Docs

Get Notification Data

When sending notifications with ReturnMode as RESUME, the response will be a RequestID that you can use to get the notification data.

This service will return information about the number of notifications sent, processed and processing.

POST variables

  • HASH: Hash of the company where the template is registered
  • ANNAEXEC: The generated IV, which will be used to encrypt the values of other variables
  • SentId: The generated ID when sending notifications in ReturnMode = RESUME

Examples

public static string Execute_WebService()
{
  string DecKey = "DECRYPTION_KEY";
  string EncKey = "ENCRYPTION_KEY";
  string Hash = "COMPANY_HASH";

  // Generate new IV
  TripleDESCryptoServiceProvider auxTdes = new TripleDESCryptoServiceProvider();
  auxTdes.GenerateIV();
  byte[] IVArray = auxTdes.IV;
  string IV = Convert.ToBase64String(IVArray);

  string sentId = "NOTIFICATION_ID";
  string sentIdEncriptado = Encrypt3DES(sentId, EncKey, IV);

  string dadosPost = "HASH=" + Uri.EscapeDataString(Hash);
  dadosPost += "&ANNAEXEC=" + Uri.EscapeDataString(IV);
  dadosPost += "&sentId=" + Uri.EscapeDataString(sentIdEncriptado);
  byte[] dados = Encoding.UTF8.GetBytes(dadosPost);

  string url = "https://YOUR_ANNA_URL/aannagetnotificationdata.aspx";
  WebRequest requisicaoWeb = WebRequest.Create(url);
  requisicaoWeb.Method = "POST";
  requisicaoWeb.ContentType = "application/x-www-form-urlencoded";
  requisicaoWeb.ContentLength = dados.Length;

  Stream dataStream = requisicaoWeb.GetRequestStream();
  dataStream.Write(dados, 0, dados.Length);
  dataStream.Close();

  WebResponse response = requisicaoWeb.GetResponse();

  using (dataStream = response.GetResponseStream())
  {
      StreamReader reader = new StreamReader(dataStream);

      string responseFromServer = reader.ReadToEnd();
      if (responseFromServer.Contains(IV))
      {
          string novoIVEncriptado = responseFromServer.Substring(responseFromServer.IndexOf(IV));
          novoIVEncriptado = novoIVEncriptado.Replace(IV, "");
          string retornoEncriptado = responseFromServer.Substring(0, responseFromServer.IndexOf(IV));

          string novoIV = Decrypt3DES(novoIVEncriptado, EncKey, IV);
          string retorno = Decrypt3DES(retornoEncriptado, DecKey, novoIV);

          response.Close();

          return retorno;
      }
      else
      {
          response.Close();
          return responseFromServer;
      }
  }
}