title: How to fetch User ID from OneSignal using JavaScript?
body: <p>I have a OneSignal CURL code implemented in my webview app which sends notifications to every single user.</p>
  <p>To target a specific user based on userid from OneSignal, i tried below code to fetch userID</p>
  <pre><code>&lt;script src=&quot;https://cdn.onesignal.com/sdks/OneSignalSDK.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;
  
    window.OneSignal = window.OneSignal || [];
    OneSignal.push(function() {
      OneSignal.init({
        appId: &quot;xxxxx&quot;,
      });
      OneSignal.on('subscriptionChange', function (isSubscribed) {
          console.log(&quot;The user's subscription state is now:&quot;, isSubscribed);
          OneSignal.getUserId(function(userId) {
            console.log(&quot;OneSignal User ID:&quot;, userId);
            // (Output) OneSignal User ID: 270a35cd-4dda-4b3f-b04e-41d7463a2316    
           });
      });
    });
  </code></pre>
  <p>// Out put was nothing, maybe <strong>subscriptionchange</strong> was not true.</p>
  <p>And also this:</p>
  <pre><code>window.OneSignal = window.OneSignal || [];
    OneSignal.push(function() {
      OneSignal.init({
        appId: &quot;abbd6373-f394-4912-a314-40493c2a6201&quot;,
      });
       OneSignal.getUserId(function(userid){
          console.log(userid);
          $(&quot;.some&quot;).html(userid);
        });
    });
  </code></pre>
  <p>//Output <strong>'NULL'</strong> on userid.</p>
  <p>I all want to do is fetch the userid from OneSignal and use it on below code to target specific user:</p>
  <pre><code>notify(&quot;Alert&quot;,&quot;Testing Notification&quot;);
          $content = array(&quot;en&quot; =&gt; &quot;Testing Notification &quot;);
          $fields = array(
              'app_id' =&gt; &quot;xxxxxx&quot;,
              'included_segments' =&gt; array('All'),
              'contents' =&gt; $content,
              'data' =&gt; array(&quot;en&quot; =&gt; &quot;bar&quot;),
              'large_icon' =&gt;&quot;ic_launcher_round.png&quot;,
          );
      
      $fields = json_encode($fields);
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, &quot;https://onesignal.com/api/v1/notifications&quot;);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
          'Content-Type: application/json; charset=utf-8',
          'Authorization: Basic xxxxxx'
      ));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, FALSE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      
      $response = curl_exec($ch);
      curl_close($ch);
  </code></pre>
  <p>Any help is greatly appreciated..</p>