CORS problem when using the API

Hi all,
I’m developing a panel where there are quick Piwik statistics, now the problem is that Piwik is installed into server 1 and the other application is installed in local. When i attempt to use the API provided by Piwik with a jquery script it show CORSS error.

I tried this How do I configure my Piwik server to allow cross domain requests? (CORS) - Analytics Platform - Matomo but nothing changed.

The jquery script.


$.ajax({
		url: 'http://www.andreacatania.com/piwik/index.php',
		data: {   module: 'API'
				, method: 'Actions.getPageUrl'
				, idSite: 1
				, period: 'range'
				, date: 'last7'
				, pageUrl: pageUrl
				, format: 'json'
				, token_auth: '7917f2596f8bb70c954893f200ba6274'
				, crossDomain: true
			},
		type: 'get',
		dataType: 'json',
		success: function( data ){
			alert( data.sum_daily_entry_nb_uniq_visitors );
		},
		error: function(response, ajaxOptions, thrownError) {
			console.log( ajaxOptions + ': ' + thrownError );
		}
	});

The error returned by jquery script.


Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.andreacatania.com/piwik/index.php?module=API&method=Actions.getPageUrl&idSite=1&period=range&date=last7&pageUrl=%2Fcpumper%2Ftest&format=json&token_auth=7917f2596f8bb70c954893f200ba6274&crossDomain=true. This can be fixed by moving the resource to the same domain or enabling CORS.

What i have to do to avoid it?

Thanks in advance have a nice day, Byee.

1 Like

Hi there, you can configure Piwik to allow Cross origin resource sharing, see this faq; How do I configure my Piwik server to allow cross domain requests? (CORS) - Analytics Platform - Matomo

1 Like

I’m facing the same issue as well. Eventhough I have cors_domains[] = * enabled, I still see the response header as -
Access-Control-Allow-Origin: https://localhost

I am having the same issue, is there a solution for this? I clicked the link above referencing the other ticket and it’s not there:

Here is more of the response:

Preformatted textAccess to XMLHttpRequest at ‘https://mynapatools.matomo.cloud/index.php?&module=API&method=Referrers.getKeywords&idSite=1&date=1561743256926&period=range%26date%3D1561743256896%2Cyesterday&format=json&filter_limit=10&token_auto=…5&crossDomain=true’ from origin ‘https://test2015.mynapatools.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
(index):307 error:
jquery.js:4 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://mynapatools.matomo.cloud/index.php?&module=API&method=Referrers.getKeywords&idSite=1&date=1561743256926&period=range%26date%3D1561743256896%2Cyesterday&format=json&filter_limit=10&token_auto=…&crossDomain=true with MIME type application/json.

do you have another link for this, this one is dead.

bueller… bueller… bueller…

1 Like

i added my domain to matomo and I still have the problem.
domain: mydomain.com
image

the api request is : "https://" + piwikServerUrl+ "/?module=API&method=UsersManager.userExists&token_auth=number&userLogin=" + loginname;

Any idea to solve the CORS policy with matomo ?

Hi Jmalan, Any news ? did you solde the problem of cors with matomo .