title: Magento OAuthException: Invalid auth/bad request got a 400
body: <p>I'm dying for this painfull issue with magento REST API. 
  I can get the orders using REST API. Only when I try to create a product using POST method I get the following error.
  My PHP code I tried with is given below.</p>
  
  <pre><code>function upload_to_store($id=null,$product_data=null)
  {
      /**
       * Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
       */
      $callbackUrl = site_url() . "admin_products/upload_to_store/".$id;
      $temporaryCredentialsRequestUrl = "url" . urlencode($callbackUrl);
      $adminAuthorizationUrl = 'oauth_authorize';
      $accessTokenRequestUrl = 'token url';
      $apiUrl = 'api url';
      $consumerKey = '';
      $consumerSecret = '';
      session_start();
      if (!isset($_GET['oauth_token']) &amp;&amp; isset($_SESSION['state']) &amp;&amp; $_SESSION['state'] == 1) {
          $_SESSION['state'] = 0;
      }
      try {
          $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
          $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
          $oauthClient-&gt;enableDebug();
          if (!isset($_GET['oauth_token']) &amp;&amp; !$_SESSION['state']) {
              $requestToken = $oauthClient-&gt;getRequestToken($temporaryCredentialsRequestUrl);
              $_SESSION['secret'] = $requestToken['oauth_token_secret'];
              $_SESSION['state'] = 1;
              header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
              exit;
          } else if ($_SESSION['state'] == 1) {
              $oauthClient-&gt;setToken($_GET['oauth_token'], $_SESSION['secret']);
              $accessToken = $oauthClient-&gt;getAccessToken($accessTokenRequestUrl);
              $_SESSION['state'] = 2;
              $_SESSION['token'] = $accessToken['oauth_token'];
              $_SESSION['secret'] = $accessToken['oauth_token_secret'];
              header('Location: ' . $callbackUrl);
              exit;
          } else {
              $oauthClient-&gt;setToken($_SESSION['token'], $_SESSION['secret']);
              $resourceUrl = "$apiUrl/products";
              $productData = json_encode(array(
                  'type_id' =&gt; 'simple',
                  'attribute_set_id' =&gt; 4,
                  'sku' =&gt; $product_data['sku'],
                  'weight' =&gt; $product_data['weight'],
                  'status' =&gt; 1,
                  'visibility' =&gt; 4,
                  'name' =&gt; $product_data['name'],
                  'description' =&gt; $product_data['description'],
                  'short_description' =&gt; $product_data['short_description'],
                  'price' =&gt; $product_data['price'],
                  'tax_class_id' =&gt; 0,
  
              ));
              $oauthClient-&gt;disableRedirects();
              $headers = array('Content-Type' =&gt; 'application/json', 'Content_Type' =&gt; 'application/json');
              $oauthClient-&gt;fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
              $response = $oauthClient-&gt;getLastResponseInfo();
              if (isset($response['url'])) {
                  header('Location: ' . $response['url']);
              }
          }
          return true;
      } catch (OAuthException $e) {
          print_r($e);
      }}
  </code></pre>
  
  <p>I get this error:
  <code>OAuthException: Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)</code></p>
  
  <p>How can I get rid of this?
  Thanks in advance.</p>