cancel
Showing results for 
Search instead for 
Did you mean: 

CORS Error when making AJAX Post Request to Create Webhook

Getting error " The 'Access-Control-Allow-Origin' header has a value 'https://developer.authorize.net' that is not equal to the supplied origin." making POST request. Javascript request code below. Working in Sandbox.

 

    var transaction_key = "[key]";
    var api_login_id = "[login_id]";

    $.ajax({
        headers: {
            "Authorization": "Basic " + btoa(api_login_id + ":" + transaction_key)
        },
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({
            "name": "My New Webhook",
            "url": "[my URL]",
            "eventTypes": [
                "net.authorize.payment.authcapture.created",
                "net.authorize.customer.created",
                "net.authorize.customer.paymentProfile.created",
                "net.authorize.customer.subscription.expiring"
            ],
            "status": "active"
        }),
        dataType: "json",
        success: function (response) {
            console.log(response);
        }
    });
dvieira
Member
1 REPLY 1
  1. Authorize Your Domain: Make sure that "https://developer.authorize.net" is listed as an authorized domain in the CORS headers on the server status at :https://apitest.authorize.net. This involves configuring the server to include the 'Access-Control-Allow-Origin' header with the value 'https://developer.authorize.net' in its responses.

  2. Wildcard (*) Approach: If possible, configure the server to respond with a wildcard '*' as the 'Access-Control-Allow-Origin' header, allowing any domain to access its resources. This is less secure and should be used cautiously, mainly in development environments.

  3. Proxy Server: Set up a proxy server on your domain that forwards requests to "https://apitest.authorize.net." This way, the request appears to come from the same domain, avoiding CORS issues.

Marsh
marshray
Member