Title: Coinbase API returning "product not found" for valid product ID
Tags: javascript;node.js;rest;post;coinbase-api
Question: I'm using the sandbox API at the moment, and I can query the products, including individually, but if I try and place a buy order, the response I get is ```{ message: 'Product not found' }```.
Here's my code:
```async function cb_request( method, path, headers = {}, body = ''){

  var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
      apiSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
      apiPass = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

  //get unix time in seconds
  var timestamp = Math.floor(Date.now() / 1000);

  // set the request message
  var message = timestamp + method + path + body;

  //create a hexedecimal encoded SHA256 signature of the message
  var key = Buffer.from(apiSecret, 'base64');
  var signature = crypto.createHmac('sha256', key).update(message).digest('base64');

  //create the request options object
  var baseUrl = 'https://api-public.sandbox.pro.coinbase.com';

  headers = Object.assign({},headers,{
      'CB-ACCESS-SIGN': signature,
      'CB-ACCESS-TIMESTAMP': timestamp,
      'CB-ACCESS-KEY': apiKey,
      'CB-ACCESS-PASSPHRASE': apiPass,
      'USER-AGENT': 'request'
  });

  // Logging the headers here to ensure they're sent properly
  console.log(headers);

  var options = {
      baseUrl: baseUrl,
      url: path,
      method: method,
      headers: headers
  };

  return new Promise((resolve,reject)=&gt;{
    request( options, function(err, response, body){
      if (err) reject(err);
      resolve(JSON.parse(response.body));
    });
  });

}

async function main() {
  
  // This queries a product by id (successfully)
  try {
     console.log( await cb_request('GET','/products/BTC-USD') );
  }
  catch(e) {
     console.log(e);
  }

  // Trying to place a buy order here (using the same id as above) returns { message: 'Product not found' }
  var buyParams = {
    'type': 'market',
    'side': 'buy',
    'funds': '100',
    'product_id': 'BTC-USD'
  };

  try {
    var buy = await cb_request('POST','/orders',buyParams);
    console.log(buy);
  }
  catch(e) {
     console.log(e);
  }

}

main();
```
I've tried sending the params in the body, which responds with ```invalid signature```, even when stringified. I've also tried using the params shown in the API docs, but that responds with ```product not found``` too.
Any ideas? TIA

Comment: Could be a weird permission error. Do you have "trade" permission?

Comment: Also if you make a GET call on the /products endpoint to you get the product ID for BTC-USD?

Comment: Is this applying to any order types or specifically market orders?

Here is the accepted answer: As j-petty mentioned you need to send data as request body for POST operation as described in the API documentation so this is why you get &quot;product not found&quot;.
Here is working code based on what your shared:
```   var crypto = require('crypto');
    var request = require('request');
    
    async function cb_request( method, path, headers = {}, body = ''){
    
      var apiKey = 'xxxxxx',
          apiSecret = 'xxxxxxx',
          apiPass = 'xxxxxxx';
    
      //get unix time in seconds
      var timestamp = Math.floor(Date.now() / 1000);
    
      // set the request message
      var message = timestamp + method + path + body;
      console.log('######## message=' + message);
    
      //create a hexedecimal encoded SHA256 signature of the message
      var key = Buffer.from(apiSecret, 'base64');
      var signature = crypto.createHmac('sha256', key).update(message).digest('base64');
    
      //create the request options object
      var baseUrl = 'https://api-public.sandbox.pro.coinbase.com';
    
      headers = Object.assign({},headers,{
        'content-type': 'application/json; charset=UTF-8',
          'CB-ACCESS-SIGN': signature,
          'CB-ACCESS-TIMESTAMP': timestamp,
          'CB-ACCESS-KEY': apiKey,
          'CB-ACCESS-PASSPHRASE': apiPass,
          'USER-AGENT': 'request'
      });
    
      // Logging the headers here to ensure they're sent properly
      console.log(headers);
    
      var options = {
          'baseUrl': baseUrl,
          'url': path,
          'method': method,
          'headers': headers,
          'body': body
    
      };
    
      return new Promise((resolve,reject)=&gt;{
        request( options, function(err, response, body){
          console.log(response.statusCode + &quot;  &quot; + response.statusMessage);
          if (err) reject(err);
          resolve(JSON.parse(response.body));
        });
      });
    
    }
    
    async function main() {
      
      // This queries a product by id (successfully)
      try {
        console.log('try to call product-------&gt;');
         console.log( await cb_request('GET','/products/BTC-USD') );
         console.log('product-------------------&gt;done');
      }
      catch(e) {
         console.log(e);
      }
    
      var buyParams = JSON.stringify({
        'type': 'market',
        'side': 'buy',
        'funds': '10',
        'product_id': 'BTC-USD'
      });
    
      try {
        console.log('try to call orders-------&gt;');
        var buy = await cb_request('POST','/orders', {}, buyParams);
        console.log(buy);
        console.log('orders-----------------------&gt;done');
    
      }
      catch(e) {
         console.log(e);
      }
    
    }
    
    main();
```



Here is another answer: It's worth mentioning that the sandbox API has different results than the production API. Consider the following CURLs.
Sandbox API:
```❯ curl --request GET \
     --url https://api-public.sandbox.exchange.coinbase.com/products/ETH-USD \
     --header 'Accept: application/json'
{&quot;message&quot;:&quot;NotFound&quot;}%
```
Production API:
```❯ curl --request GET \
     --url https://api.exchange.coinbase.com/products/ETH-USD \
     --header 'Accept: application/json'
{&quot;id&quot;:&quot;ETH-USD&quot;,&quot;base_currency&quot;:&quot;ETH&quot;,&quot;quote_currency&quot;:&quot;USD&quot;,&quot;base_min_size&quot;:&quot;0.00029&quot;,&quot;base_max_size&quot;:&quot;2800&quot;,&quot;quote_increment&quot;:&quot;0.01&quot;,&quot;base_increment&quot;:&quot;0.00000001&quot;,&quot;display_name&quot;:&quot;ETH/USD&quot;,&quot;min_market_funds&quot;:&quot;1&quot;,&quot;max_market_funds&quot;:&quot;4000000&quot;,&quot;margin_enabled&quot;:false,&quot;fx_stablecoin&quot;:false,&quot;max_slippage_percentage&quot;:&quot;0.02000000&quot;,&quot;post_only&quot;:false,&quot;limit_only&quot;:false,&quot;cancel_only&quot;:false,&quot;trading_disabled&quot;:false,&quot;status&quot;:&quot;online&quot;,&quot;status_message&quot;:&quot;&quot;,&quot;auction_mode&quot;:false}%
```
You'll notice that the paths are identical but you get different results so keep that in mind. For testing purposes BTC-USD can be used.


Here is another answer: You need to send a POST request to the ```/orders``` endpoint and include the body in the request payload.
There are some example answers in this question.
```var options = {
    baseUrl: baseUrl,
    url: path,
    method: method,
    headers: headers
    json: true,
    body: body
}

request.post(options, function(err, response, body){
  if (err) reject(err);
  resolve(JSON.parse(response.body));
});
```

Comment for this answer: Thanks for your answer. I've tried sending it in the body and parsing it beforehand etc. but I'm getting an `invalid signature` response.
Comment for this answer: Have you tried using `JSON.stringify()` on the body object when generating the signature as shown in the [documentation](https://docs.pro.coinbase.com/?javascript#signing-a-message)? Reason being if this is the operation they're using when validating the payload matches your signature, you'll need to do the same thing. The difference between a ' and a " for example will result in an incorrect signature.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:04/05/21', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<javascript><node.js><rest><post><coinbase-api>', 'Title': 'Coinbase API returning "product not found" for valid product ID', 'ViewCount': 1357, 'id': 66959274, 'user_AboutMe': None, 'user_AccountId': 2069791.0, 'user_DisplayName': 'AJT', 'user_Reputation': 350.0, 'user_Views': 99.0, 'user_id': 1844520.0}}