Getting Cross Origin Block Request [CORS] error when using .getJSON to get Play Store App Details

Getting Cross Origin Block Request [CORS] error when using .getJSON to get Play Store App Details

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Getting Cross Origin Block Request [CORS] error when using .getJSON to get Play Store App Details

A CORS (Cross-Origin Resource Sharing) error blocks your application from reading a remote resource, even if that resource is accessible via direct browser navigation. This distinction between "accessible" and "readable" is the core of the issue you are facing with the 42matters API. When you manually enter the URL in a browser, the request succeeds because the browser treats direct navigation differently than programmatic requests initiated by JavaScript. However, as soon as your client-side code attempts to parse the JSON response using jQuery's $.getJSON, the Same-Origin Policy intervenes and blocks the read operation unless the server explicitly permits it.

The root cause lies in how modern browsers enforce security boundaries. When your web application running on one domain (or a different port) requests data from https://42matters.com, the browser intercepts the response before your JavaScript can access it. If the server hosting the API does not include specific headers indicating that cross-origin requests are allowed, the browser throws the Cross-Origin Request Blocked error you observed.

Attempting to resolve this by modifying server configurations on the target domain is often futile if you do not have administrative control over that specific server stack. You mentioned trying to enable CORS using PHP and adjusting Apache configuration files. While adding headers like Access-Control-Allow-Origin in a PHP script is the correct approach for a PHP backend, changing the global httpd.conf or .htaccess file on a third-party service you do not host will either fail to apply or be overwritten by their own security policies. Furthermore, restarting a remote Apache service via configuration changes is impossible if you are not running the server locally; those services must be managed by the hosting provider of 42matters.com.

Since you cannot modify the server-side headers for the 42matters API, your solution must reside entirely within your client-side application. The standard workaround is to use a CORS proxy service that accepts requests from your origin, forwards them to the target API, and returns the response with the necessary headers stripped or re-injected appropriately.

Here is how you can refactor your jQuery code to bypass the browser's security check using a public proxy like cors-anywhere:

var packageID = 'com.whatsapp';
// Using a CORS proxy to intercept the request and add required headers
$.getJSON('https://cors-anywhere.herokuapp.com/https://42matters.com/api/1/apps/lookup.json?p=' + packageID + '&access_token=accesstoken1234')
.done(function(appDetails) {
    // Debugging: Log the object instead of stringifying immediately to inspect structure
    console.log('App Details:', appDetails); 
    $('#logo').html(JSON.stringify(appDetails));
}).fail(function(error) {
    console.error("Request failed:", error);
});

While proxying is a quick fix, it introduces latency and relies on the availability of third-party services. A more robust architectural pattern involves moving the API call to your own backend server. In a Laravel application, for instance, you would fetch the data from 42matters.com using a standard HTTP client like Guzzle or the built-in Http facade.

// Example within a Laravel controller
use Illuminate\Support\Facades\Http;

public function getAppDetails($packageID)
{
    $response = Http::withHeaders([
        'Accept' => 'application/json',
    ])->get('https://42matters.com/api/1/apps/lookup.json', [
        'p' => $packageID,
        'access_token' => 'accesstoken1234', // Ensure this is secure in production
    ]);

    if ($response->successful()) {
        return response()->json($response->json());
    }

    return response()->json(['error' => 'Failed to fetch app details'], 500);
}

Once your Laravel backend retrieves the data, you can serve it to your frontend via a standard AJAX call or even a simple HTML <script> tag. Because both your frontend and backend run on the same domain (or the backend exposes an endpoint trusted by your frontend), the Same-Origin Policy will not block the request. This approach eliminates the need for external proxies and ensures that sensitive data remains within your controlled infrastructure.

It is also worth noting that some APIs offer a specific JSONP callback parameter, such as callback=jQuery123456, which allows cross-origin requests without modifying headers. However, this method is deprecated in modern JavaScript development and does not support complex data structures or binary content as reliably as standard JSON over CORS-enabled endpoints. If the 42matters API documentation supports a callback parameter, you could attempt:

$.getJSON('https://42matters.com/api/1/apps/lookup.json?p=' + packageID + '&access_token=accesstoken1234&callback=?')
.done(function(appDetails) {
    // Handle response here
});

If the API does not support JSONP or if you require more control over the request lifecycle, implementing a backend proxy remains the industry-standard solution for handling third-party APIs with restrictive CORS policies.

Our network