Skip to main content

I'm getting a 'Blocked by CORS policy' error with the API

CORS blocking your API? Move calls to backend to protect tokens and prevent security risks from exposed credentials.

River Sloane
Updated by River Sloane

If you're seeing this error when trying to use the HelpDocs API, it means your current setup isn't quite right. The good news is this error is actually protecting you from a security vulnerability āœ‹

What's happening here?

CORS (Cross-Origin Resource Sharing) is a security feature built into web browsers. When you try to make API calls directly from your frontend code (like JavaScript running in a browser), the browser blocks these requests to protect your API credentials.

This error appears when you're trying to use the HelpDocs API from frontend code, which exposes your API token to anyone who visits your website.

Why this is a security risk

When you use API tokens in frontend code, they become visible to anyone who inspects your website. This means bad actors could steal your token and access your Knowledge Base data.

Your API token should be treated like a password. Just like you wouldn't put your password in JavaScript code that anyone can read, you shouldn't put your API token there either.

The secure solution

The fix is simple: move your API calls to your backend server instead of making them directly from the browser. Here's what you should do:

  1. Remove the API token from your frontend code
  2. Create an endpoint on your backend server that handles the API calls
  3. Have your frontend make requests to your own backend endpoint
  4. Your backend then securely calls the HelpDocs API using the token
This approach also gives you more control over what data gets sent to your frontend and lets you cache responses for better performance.

Need help with implementation?

Check out our API documentation for detailed examples of secure API usage. The docs include sample code for various programming languages that show the proper backend implementation.

If you're building a chatbot that needs to access your Knowledge Base content, consider using our Chatbot Source Page which provides a secure way to feed your content to AI systems.

What did you think of this doc?

Can I have a single article appear in multiple categories?

How do I change my email?

Get in touch

This site is protected by hCaptcha and its Privacy Policy and Terms of Service apply.