Jul 15, 20213:38 AM - edited Jul 15, 20213:39 AM
Member
How to fix cors is not allowing API request issue
SOLVE
I'm using hubspot create contact API. My front end is react JS application.
I have added my domain in Additional site domains as well. But still I'm facing CORS issue while POST API request. Anything else do I need to do for CORS issue ?
@AKinwad - Please, do not post directly to the contacts API from the browser.
You need to create a function on a server that makes the request for you, this will allow you to obfuscate your API KEY. This is also the reason you are having CORS issues..
I personally use PHP but, you can use Node, Ruby, Python, etc....
@AKinwad - Please, do not post directly to the contacts API from the browser.
You need to create a function on a server that makes the request for you, this will allow you to obfuscate your API KEY. This is also the reason you are having CORS issues..
I personally use PHP but, you can use Node, Ruby, Python, etc....
Thank you fior your response. However, I tried editing my POST api call as your above example but still getting CORS issue. Let me know if you need more info from my side.
Im using versel to deploy my frontity react application. Im using frontity in my react application.
You have required serverless function on creating option in design tools in hubspot. If you are using react app then your actually domain and ajax url domain will be same then cors error not occur. firstly you send request to serverless function using ajax then call api using axios in node.js.
Example code of serverless for how to get deal using serverless function : // Require axios to make API requests in the function const axios = require("axios"); const request = require("request");