IONIC Notification push error “Permission Denied” with API

i am doing an app using ionic 2 Typescript and angular 2 and i am including push notifications in it. The notifications are setup correctly on the client side. when i set up the server to send the notifications dynamically it responds with error: Permission denied to connect to

this is the server side code :

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "",
        "Authorization: Bearer $token",
        "Content-Type: application/json"

$response = curl_exec($curl);
$err = curl_error($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    //echo $response;

The problem is that this code works perfectly when i try it locally and it does connect to the API and send notifications to devices.

Note: I don’t have access to the distant server on which the problem occurs.

Anyone has an idea on how to solve this error ?

I’m using nodejs for serverside and I added crossplatform like Access-Control-Allow-Headers and solved are you using it?

I can’t really access the Server in which i am hosting the Php file, so i really can’t add those headers

Sorry I’m not so qualified with php good luck :slight_smile:

Can you post the complete error you are getting please?

Failed to connect to Permission denied , Just that.

That doesn’t really make sense as the PHP code adds a cURL Error #: before the error output. If this error is thrown by someone else in the script, make sure to find out where exactly and why.

$response2 = curl_exec($curl);
                $err = curl_error($curl);
                if ($err) {
                    echo " R2 cURL Error #:" . $err;
                } else {
                    echo $response2;

this is the error code and the error message $err is the error message i posted earlier

And still it only outputs “Permission denied to connect to”?

yes that is the text from the echo $err

There is no echo $err; in your code.

That is what i meant

Ok, so curl_exec is “returning” that error.

Can you also use so we can check the specific error at

I did echo the curl_errno and it returned 7
and this is the the definition if the number 7


Failed to connect() to host or proxy.

i think i need to add a parameter to the server’s configuration but i don’t know what to add.
Note : I have full access to the server i am hosting the php file on.

Can cURL connect to any other website like or anything?

Yes it can connect to google

I fixed this actually by adding the IP that i get in the error message as an outgoing connection so that the server would let it pass. But what i noticed is that the ip in the error message changes from… to… so i can not exactly add all possible ip addresses as outgoing connections. I am still stuck with this now.

What does that mean?

There is an option in the server i am using to host the php file called restrict outgoing connections. it restricts any connections or requests done by the server to external IPs, so i completely disabled that and the requests to ionic notification API are now working as intended.

1 Like

All Ionic services sit behind a CDN via Cloudflare (I think) and a load balancer at heroku or Amazon so it is normal to be serviced by different IPs.