title: Is it possible to upload APNS Certificates to the azure notification hub programatically or via the CLI
body: <p>We are investigating the azure notification hub, and while we have had success sending/receiving messages from it, we also require programatic configuration of the hub.</p>
  
  <p>It seems that the only way possible to create the notification hub is via the azure cli with an azuredeploy.json ARM template like <a href="https://github.com/Azure/azure-quickstart-templates/blob/master/101-notification-hub/azuredeploy.json" rel="nofollow noreferrer">this one</a>. However, I can't find any information about adding an APNS certificate to that. </p>
  
  <p>Looking at the Automation Script generated from our hub, there is no evidence of the google firebase API key or the APNS certificate. Is this possible or do these need to be done through the azure portal at all times.</p>
  
  <p>UPDATED: I have managed to create a notification hub namespace using the arm template with little issue, however I am getting a "bad request" (correlation id - 3faee649-7084-436d-8d7e-4a9c6f79cc4e) when trying to create the notification hub itself with the apns certificate. </p>
  
  <p><a href="https://stackoverflow.com/questions/40842783/how-to-configure-the-apns-certificate-in-the-arm-template">this post</a> is someone having a similar problem, however their key for the apns is a lot shorter than mine. I literally created a base64 string from the certificate file which is 5000+ characters wrong, I assume that is incorrect, but I can't figure out what value from apple is meant to go in here.</p>
  
  <p>My template looks like this:</p>
  
  <pre><code>    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "Gcm.GoogleApiKey": {
        "type": "string",
        "metadata": {
          "description": "Google Cloud Messaging API Key"
        },
        "defaultValue": ""
      },
      "Apns.apnsCertificate": {
          "type": "string",
          "metadata": {
            "description": "A certificate (in base 64 format) provided by Apple on the iOS Provisioning Portal"
          }
        },
        "Apns.certificateKey": {
          "type": "string",
          "metadata": {
            "description": "The Certificate Key provided by the iOS Provisioning Portal when registering the application"
          },
          "defaultValue": ""
        },
        "Apns.endpoint": {
          "type": "string",
          "metadata": {
            "description": "The APNS endpoint to which our service connects. This is one of two values: gateway.sandbox.push.apple.com for the sandbox endpoint or gateway.push.apple.com, for the production endpoint. Any other value is invalid"
          },
          "defaultValue": "gateway.sandbox.push.apple.com"
        }
    },
    "variables": {
      "hubVersion": "[providers('Microsoft.NotificationHubs', 'namespaces').apiVersions[0]]",
      "notificationHubNamespace": "[concat('hubv2', uniqueString(resourceGroup().id))]",
      "notificationHubName": "notificationhub"
    },
    "resources": [
      {
        "name": "[variables('NotificationHubNamespace')]",
        "location": "[resourceGroup().location]",
        "type": "Microsoft.NotificationHubs/namespaces",
        "apiVersion": "2017-04-01",
        "comments": "Notification hub namespace",
        "properties": {
          "namespaceType": "NotificationHub"
        },
        "resources": [
          {
            "name": "[concat(variables('NotificationHubNamespace'),'/',variables('NotificationHubName'))]",
            "location": "[resourceGroup().location]",
            "type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
            "apiVersion": "2017-04-01",
            "properties": {
              "GcmCredential": {
                "properties": {
                  "googleApiKey": "[parameters('Gcm.GoogleApiKey')]",
                  "gcmEndpoint": "https://android.googleapis.com/gcm/send"
                }
              },
              "apnsCredential": {
                  "properties": {
                      "apnsCertificate" : "[parameters('Apns.apnsCertificate')]",
                      "certificateKey" : "[parameters('Apns.certificateKey')]",
                      "endpoint" : "[parameters('Apns.endpoint')]"
                  }
              }
            },
            "dependsOn": [
              "[concat('Microsoft.NotificationHubs/namespaces/', variables('NotificationHubNamespace'))]"
            ]
          }
        ]
      }
    ],
    "outputs": {
    }
  }
  </code></pre>