Unable to make a request to /api/v3/brokerage/products/{product_id}/candles/ endpoint without error

Hi there,
Is anyone able to get the /api/v3/brokerage/products/{product_id}/candles/ endpoint to return data?

This is the error that is returned to me regardless of the granularity and the fact that the start and end are within 300 candles of each other StatusCodeError: 400 - error:“INVALID_ARGUMENT” - error_details:"start and end argument is invalid - number of candles requested should be less than 300 ".

		const method = 'GET';
		const path = '/api/v3/brokerage/products/BTC-USD/candles';
		const body = '';

		function sign(str, apiSecret) {
			const hash = CryptoJS.HmacSHA256(str, apiSecret);
			return hash.toString();

		const timestamp = Math.floor(Date.now() / 1000).toString();
		const str = timestamp + method + path + body;
		const sig = sign(str, secret);

		const options = {
			method: 'GET',
			timeout: 10000,
			url: `https://api.coinbase.com${path}?granularity=ONE_DAY&start=${new Date(
				'01 January 2023',
			).getTime()}&end=${new Date('15 January 2023').getTime()}`,
			headers: {
				'Content-Type': 'application/json',
				'CB-ACCESS-KEY': key,
				'CB-ACCESS-SIGN': sig,
				'CB-ACCESS-TIMESTAMP': timestamp,
			json: true,

Hi @Tradable! Thank you for taking an interest in trying out Coinbase APIs. For the details regarding your inquiry, we will check on this for you with our team to see how we can best assist. We’ll get back to you once we have more information. Keep in touch!

Thank you, please let me know what you find, because I’m unable to use that endpoint at the moment

Hi @Tradable! Thank you so much for patiently waiting while we look into this. Upon checking the code snippet you provided, it looks like you have an extra comma in your URL creator:

url: [https://api.coinbase.com](https://api.coinbase.com/)${path}?granularity=ONE_DAY&start=${new Date('01 January 2023',).getTime()}&end=${new Date('15 January 2023').getTime()},

It should be:

url: [https://api.coinbase.com](https://api.coinbase.com/)${path}?granularity=ONE_DAY&start=${new Date('01 January 2023').getTime()}&end=${new Date('15 January 2023').getTime()},

We would appreciate it if you try modifying this URL creator and see if it works for you. Please do not hesitate to reply on this thread if the issue still persists.

1 Like

@Mamoshi27 thank you for your feedback. The extra comma is just a formatting adjustment provided by our linter as it’s on a new line, but javascript doesn’t register it. The date is created in the same way with or without the comma.
Is the endpoint working for you? The above example makes a request to following url:

It might be that you are not converting the start/end timestamps into seconds, similar to how your signature timestamp is created.

Thanks heaps for your help @Rainner, that was it! The API is expecting the start/end in seconds, so since we were providing milliseconds, the number of candles was thousands. Not to mention the start date would be thousands of years in the future.