Best Practices

Best Practices

Tips for building reliably with BareCommerceCore.

API Key Security

  • Keep it secret. Don't commit API keys to Git. Use environment variables.
  • Rotate regularly. Delete old keys and create new ones periodically.
  • Use minimal scopes. Only request the permissions you need.
  • Monitor usage. Check "Last Used" in your API keys dashboard to catch abuse.

Error Handling

Always handle errors gracefully:

try {
  const response = await fetch(url, options);
  
  if (!response.ok) {
    const error = await response.json();
    console.error(`API Error: ${error.error.code}`, error.error.details);
  }
  
  const data = await response.json();
  return data;
} catch (error) {
  console.error('Network error:', error);
}

Pagination

For list endpoints, use pagination:

const response = await fetch(
  `https://api.barecommercecore.com/api/stores/${storeId}/products?limit=50&offset=0`,
  { headers }
);
const { items, total } = await response.json();

Testing

Before deploying:

  1. Test with real data — Use your actual store
  2. Test error cases — What happens when an order fails?
  3. Test edge cases — What if a product has no image?
  4. Load test — Can your integration handle 100 orders/minute?

Debugging

When something breaks:

  1. Check API responses — Print the full response and error details
  2. Verify credentials — Is the API key correct? Is it active?
  3. Check store ID — Are you using the right store?
  4. Review field names — Use our API reference
  5. Ask in Discord — We're here to help

Going Live

Checklist before production:

  • API key is stored securely (environment variable)
  • Error handling is implemented
  • Webhook signatures are verified
  • Inventory sync is working
  • Order creation is tested
  • Load testing is complete

Getting Help

Happy building! 🚀