Adding a hostname to a javascript app using PHP curl

Hello! I am unable to add a hostname to the javascript app we have registered using PHP curl.

This code has been working up until recently, is there something I am doing wrong?

Thank you in advance

        $flyiotoken = "{our-fly-token}";

        $edgeapp = "https://fly.io/api/v1/apps/{our-app-name}/hostnames";

        $route_data = [
            "data" => [
                "attributes" => [
                    "hostname" => 'www.addinghostname.com'
                ]
            ]
        ];

        $headers = array(
            'Content-type: application/json',
            'Authorization: Bearer ' . $flyiotoken,
        );

        $route_ch = curl_init();
        curl_setopt($route_ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($route_ch, CURLOPT_URL, $edgeapp);
        curl_setopt($route_ch, CURLOPT_POST, 1);
        curl_setopt($route_ch, CURLOPT_POSTFIELDS, json_encode($route_data));
        curl_setopt($route_ch, CURLOPT_RETURNTRANSFER, 1);
        curl_exec($route_ch);
        curl_close($route_ch);

This is an old API URL! Try changing it to:

https://api.fly.io/api/v1/apps/{our-app-name}/hostnames

This likely worked up until we replaced our frontend proxy a few weeks ago. The api.fly.io endpoint is stable. :slight_smile:

1 Like

Thanks Kurt!