title: Working with ChannelAdvisor REST API in PHP - requests not working in CURL
body: <p>I would like to integrate with <a href="http://developers.channeladvisor.com/rest/" rel="nofollow noreferrer">ChannelAdvisor REST API</a> using the <strong>SOAP Credentials Flow</strong>.</p>
  <p>Based on their documentation, I have setup the following in <code>PostMan</code> (rest client in Chrome browser) like this:</p>
  <p><a href="https://i.stack.imgur.com/BgeIk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BgeIk.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/cjSVl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cjSVl.png" alt="enter image description here" /></a></p>
  <p>When I make the rest; the rest api server returns the expected response:</p>
  <p><a href="https://i.stack.imgur.com/tLTL7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tLTL7.png" alt="enter image description here" /></a></p>
  <p>So, I tried to replicate this in PHP with the following class:</p>
  <pre><code>&lt;?php
  
  class ChannelAdvisorREST {
  
      /**
       * ChannelAdvisor constants &amp; properties
       */
      const BASE_URL = 'https://api.channeladvisor.com/v1';
      private $config;
  
      /**
       * Class constructor
       */
      public function __construct()
      {
          $this-&gt;config = \Config::get('channeladvisor');
      }
  
      // TEST
      public function test($accountId)
      {
          // var_dump($this-&gt;config);
  
          var_dump(self::getAccessToken($accountId));
      }
      // TEST
  
      /**
       * Method to get access token from rest server.
       *
       * @param $accountId
       * @return string
       */
      private function getAccessToken($accountId)
      {
          return self::curlPOST('/oauth2/token', [
              'client_id' =&gt; $this-&gt;config['api_app_id'],
              'grant_type' =&gt; 'soap',
              'scope' =&gt; 'inventory',
              'developer_key' =&gt; $this-&gt;config['api_developer_key'],
              'password' =&gt; $this-&gt;config['api_password'],
              'account_id' =&gt; $accountId
          ]);
      }
  
      /**
       * Method to generate a HTTP POST request
       *
       * @param $endpoint
       * @param $fields
       * @return string
       */
      private function curlPOST($endpoint, $fields = array())
      {
          // Open connection
          $ch = curl_init();
  
          // Set the url, number of POST vars, POST data
          curl_setopt($ch, CURLOPT_USERPWD, $this-&gt;config['api_app_id'] .':'. $this-&gt;config['api_shared_secret']);
          curl_setopt($ch, CURLOPT_URL, self::BASE_URL . $endpoint);
          curl_setopt($ch, CURLOPT_POST, count($fields));
          curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields, '', '&amp;'));
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_HTTPHEADER, array(
              'Content-Type: application/x-www-form-urlencoded'
          ));
  
          // Execute post request
          $result = curl_exec($ch);
  
          // Close connection
          curl_close($ch);
  
          // Finished
          return $result;
      }
  }
  </code></pre>
  <p>When I execute the <strong>test($accId)</strong> method on this class, I get the following response:</p>
  <h1>boolean false</h1>
  <p>Any idea why it isn't quite working as same as the <code>PostMan</code> test?</p>
  <p>P.S. I have already verified all the config/parms etc... are correct and same as my PostMan test. This class is a snipped version from my original code (created in Laravel 4.2, but this issue is not related to Laravel).</p>