Skip to content

Cannot access Wikidata API

I’m trying to use the Wikidata API, but all I’m getting is:

Fetch API cannot load Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘‘ is therefore not allowed access. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

This is the code:

const headers = new Headers();

const origin = "";
headers.append("Origin", origin);
headers.append("Content-Type", "application/json; charset=UTF-8");

const url = "";

const query = {
    action: "wbsearchentities",
    search: "Ingmar Bergman",
    language: "en",
    limit: 20,
    format: "json",

const myInit = new Request(url + "?" + qs.stringify(query), {
    method: "GET",
    mode: "cors-with-forced-preflight",

    .then(function(res) {

I have tried JSONP as well, no success. Running the link in the browser (just without the origin parameter) gives a proper response.


So why do you add the “origin” parameter at all? Just leave it off, or add “&callback=some_function” to get JSONP.