title: Registration in Notification Hub with PHP Backend
body: <p>For user requeriments the backend must be PHP and the app client is in Ionic 2. Based on:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx</a>
  <a href="https://github.com/Azure/azure-notificationhubs-samples/tree/master/notificationhubs-rest-php" rel="noreferrer">https://github.com/Azure/azure-notificationhubs-samples/tree/master/notificationhubs-rest-php</a>
  <a href="https://github.com/webwarejp/notificationhubs-rest-php" rel="noreferrer">https://github.com/webwarejp/notificationhubs-rest-php</a></p>
  
  <p><a href="https://stackoverflow.com/questions/35941283/create-registration-notification-hub-azure-php">Create Registration Notification Hub Azure PHP</a> <strong>Important</strong></p>
  
  <p>I created this method in php API:</p>
  
  <pre><code>    $uri = $this-&gt;endpoint . $this-&gt;hubPath . "/registrations".NotificationHub::API_VERSION;
      /* print($uri); */
      $ch = curl_init($uri);
      $token = $this-&gt;generateSasToken($uri);
      $headers = [
          'Authorization: '. $token,
          'Content-Type: '."application/atom+xml;type=entry;charset=utf-8",
          'x-ms-version: 2015-01',
          'Content-Length: 0'
      ];
      $body = $this-&gt;getXmlAndroid($registrationId, $tag);
      print_r($body);
      curl_setopt_array($ch, array(
          CURLOPT_CUSTOMREQUEST =&gt; 'POST',
          CURLOPT_RETURNTRANSFER =&gt; TRUE,
          CURLOPT_SSL_VERIFYPEER =&gt; FALSE,
          CURLOPT_HTTPHEADER =&gt; $headers,
          CURLOPT_POSTFIELDS =&gt; $body
       ));
      $response = curl_exec($ch);
          // Check for errors
      if($response === FALSE){
          print_r(curl_error($ch));
          throw new Exception(curl_error($ch));
      }
  
      $info = curl_getinfo($ch);
      print_r($info);
      curl_close($ch);
  </code></pre>
  
  <p>The getXmlAndroid method is simple return xml format with GCM ID</p>
  
  <pre><code>private function getXmlAndroid($registrationId){
      return '&lt;?xml version="1.0" encoding="utf-8"?&gt;
              &lt;entry xmlns="http://www.w3.org/2005/Atom"&gt;
                  &lt;content type="application/xml"&gt;
                      &lt;GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"&gt;
                          &lt;GcmRegistrationId&gt;'.$registrationId.'&lt;/GcmRegistrationId&gt; 
                      &lt;/GcmRegistrationDescription&gt;
                  &lt;/content&gt;
              &lt;/entry&gt;';
  
   }
  </code></pre>
  
  <p>I get the GcmRegistrationId with this function in Ionic 2 app.</p>
  
  <pre><code>import { Push, PushObject, PushOptions } from '@ionic-native/push';
  ....
  const options: PushOptions = {
    android: { senderID: 'MyIDFirebaseProject'},
    ios: { alert: 'true', badge: true, sound: 'false'},
    windows: {}
  };
  pushObject.on('registration').subscribe((registration: any) =&gt; {
   console.log(registration.registrationId);
  });
  </code></pre>
  
  <p><strong>The problem is always request to Registration method in Notification  API return</strong></p>
  
  <pre><code>[http_code] =&gt; 400
  </code></pre>
  
  <p>Where 400 means the "Invalid request body. The registration could not be created because the request was malformed.". I don't understand why this happen.</p>