Why does the first request return 200,
fetch("https://api.peopledatalabs.com/v5/autocomplete?api_key=someAPIKey&field=location")
but the second returns 400/401?
fetch(`https://api.peopledatalabs.com/v5/autocomplete`, {
"api_key": "someAPIKey",
"field": "location"
});
CodePudding user response:
In the second way, you passed the option parameter (with "api_key" and "field"), not queryParams as you meant.
You can change it to work using URLSearchParams
fetch('https://api.peopledatalabs.com/v5/autocomplete?' new URLSearchParams({
api_key: "someAPIKey",
field: "location",
}))
