Wrong URL ????

Wrong URL ????

hello,

I have built the interface to the "Calendar".

See attachment 1.

The updating of the token when the time has expired is also successfully implemented. (will be automated later in the query)

Only here I have a problem.
https://www.zoho.com/calendar/help/api/get-calendar-list.html

I have attached my PHP code once as a TXT attachment.
As well as its response as an image. Attachment 2:

"Invalid URL

Unable to process your request as the URL /calendar/api/v1/calendars?category=all&showhiddencal=true is invalid."


What am I doing wrong or is the documentation no longer correct?

Many thanks for your help.

  1. <?php

    function fetch_and_renew_token() {
        $client_id = NMT::sqlObject("SELECT `val` FROM `nmt-cfg` WHERE `key` = 'zoho_client_id'; ")->val;
        $client_secret = NMT::sqlObject("SELECT `val` FROM `nmt-cfg` WHERE `key` = 'zoho_client_secret'; ")->val;
        $refresh_token = NMT::sqlObject("SELECT `val` FROM `nmt-cfg` WHERE `key` = 'zoho_refresh_token'; ")->val;

        if (!empty($client_id) && !empty($client_secret) && !empty($refresh_token)) {
            $url = 'https://accounts.zoho.eu/oauth/v2/token';
            $data = [
                'refresh_token' => $refresh_token,
                'client_id' => $client_id,
                'client_secret' => $client_secret,
                'grant_type' => 'refresh_token'
            ];

            $response = custom_curl_request($url, $data);

            if (isset($response['access_token'])) {
                $access_token = $response['access_token'];
                $expires_in = $response['expires_in'];
                $api_domain = $response['api_domain'];
                $expires_at = time() + $expires_in + 7200; // +2 Stunden

                NMT::sqlDo("INSERT INTO `nmt-cfg` (`key`, `val`) VALUES ('zoho_access_token', '$access_token') ON DUPLICATE KEY UPDATE `val` = '$access_token';");
                NMT::sqlDo("INSERT INTO `nmt-cfg` (`key`, `val`) VALUES ('zoho_token_expires_at', '$expires_at') ON DUPLICATE KEY UPDATE `val` = '$expires_at';");
                NMT::sqlDo("INSERT INTO `nmt-cfg` (`key`, `val`) VALUES ('zoho_api_domain', '$api_domain') ON DUPLICATE KEY UPDATE `val` = '$api_domain';");

                return $access_token;
            } else {
                echo '<div style="color: red;">Fehler bei der Token-Erneuerung.</div>';
                echo '<pre>' . print_r($response, true) . '</pre>';
                return null;
            }
        } else {
            echo '<div style="color: red;">Fehler: Client ID, Client Secret oder Refresh Token fehlen.</div>';
            return null;
        }
    }

    function custom_curl_request($url, $data = [], $type = 'POST', $headers = []) {
        $curlOpts = [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
            CURLOPT_CUSTOMREQUEST => $type,
            CURLOPT_SSL_VERIFYPEER => FALSE,
        ];

        if ($type === 'POST' && !empty($data)) {
            $curlOpts[CURLOPT_POSTFIELDS] = http_build_query($data);
        }

        if (!empty($headers)) {
            $curlOpts[CURLOPT_HTTPHEADER] = $headers;
        }

        $request = curl_init();
        curl_setopt_array($request, $curlOpts);
        $response = curl_exec($request);
        $curl_error = curl_error($request);
        $http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
        curl_close($request);

        if ($curl_error) {
            echo '<div style="color: red;">Curl Error: ' . htmlspecialchars($curl_error) . '</div>';
        }

        echo '<div>HTTP Code: ' . htmlspecialchars($http_code) . '</div>';
        echo '<div>Request URL: ' . htmlspecialchars($url) . '</div>';
        echo '<div>Request Headers: ' . htmlspecialchars(print_r($headers, true)) . '</div>';
        
        if ($http_code >= 400 && $http_code < 600) {
            echo '<div>Raw Response: ' . $response . '</div>';
        } else {
            echo '<div>Raw Response: ' . htmlspecialchars($response) . '</div>';
        }

        return json_decode($response, TRUE);
    }

    function fetch_calendars() {
        $access_token = NMT::sqlObject("SELECT `val` FROM `nmt-cfg` WHERE `key` = 'zoho_access_token'; ")->val;
        $api_domain = NMT::sqlObject("SELECT `val` FROM `nmt-cfg` WHERE `key` = 'zoho_api_domain'; ")->val;

        if (!empty($access_token) && !empty($api_domain)) {
            echo '<div>Verwendeter Access Token: ' . htmlspecialchars($access_token) . '</div>';
            echo '<div>Verwendete API Domain: ' . htmlspecialchars($api_domain) . '</div>';

            $url = $api_domain . '/calendar/api/v1/calendars?category=all&showhiddencal=true';
            $headers = [
                "Authorization: Bearer $access_token"
            ];

            $curl_command = "curl -X GET \"$url\" -H \"Authorization: Bearer $access_token\"";
            echo '<div>Curl Command: ' . htmlspecialchars($curl_command) . '</div>';

            $response = custom_curl_request($url, [], 'GET', $headers);

            if (isset($response['calendars'])) {
                echo '<div>Kalender erfolgreich abgerufen:</div>';
                echo '<pre>' . print_r($response['calendars'], true) . '</pre>';
            } else {
                echo '<div style="color: red;">Fehler beim Abrufen der Kalender.</div>';
                echo '<pre>' . print_r($response, true) . '</pre>';
            }
        } else {
            echo '<div style="color: red;">Fehler: Access Token oder API Domain fehlt.</div>';
        }
    }

    if (isset($_POST['fetch_calendars'])) {
        fetch_calendars();
    }

    if (isset($_POST['fetch_token'])) {
        fetch_and_renew_token();
    }
    ?>

    <form method="post" action="">
        <input type="submit" name="fetch_token" value="Fetch-Token" />
        <input type="submit" name="fetch_calendars" value="Kalender abfragen" />
    </form>

      Zoho Developer Community









                                Zoho Desk Resources

                                • Desk Community Learning Series


                                • Digest


                                • Functions


                                • Meetups


                                • Kbase


                                • Resources


                                • Glossary


                                • Desk Marketplace


                                • MVP Corner


                                • Word of the Day



                                    Zoho Marketing Automation
                                        • Topic Participants

                                        • test

                                            • Sticky Posts

                                            • The year that was at Zoho Calendar 2023- Part 1

                                              Hello, amazing community members! Happy new year from all of us here at Zoho Calendar. As we begin the new year, we'd like to thank each and everyone of our community members for your unwavering support and love that you have shown for Zoho Calendar.
                                            • What's new in Zoho Calendar!

                                              Hello all, Greeting from Zoho Calendar! Hope you are all doing well! We at Zoho Calendar are constantly striving to improve our Calendar to enhance your overall calendaring experience thanks to your insightful suggestions and feedback. In the last few
                                            • Enhancements to make Zoho Calendar more accessible and handy!

                                              Hello, Community! Hope you're all doing well! Zoho Calendar have come across a major revamp a year back. Since then the feedback and suggestions given by you made us to improve and enhance Calendar, to make it more accessible and user friendly. We've
                                            • Important announcement: Deprecation of Zoho Calendar's old interface

                                              Hello All! Thank you all for the amazing welcome to the release of the new Calendar. Here are some comments about the new interface that motivated us:  Many of our users who were using the older version for a long period, loved the new Calendar, as it
                                            • What's new in the revamped calendar - An overview of user interface and features

                                              Hello Everyone, Scheduling meetings and events using online calendars has become inevitable as almost the entire business world has gone online. Keeping track of events, meetings and appointments has become a necessity. To serve you better, we at Zoho have


                                            Manage your brands on social media



                                                  Zoho TeamInbox Resources

                                                    Zoho DataPrep Resources



                                                      Zoho CRM Plus Resources

                                                        Zoho Books Resources


                                                          Zoho Subscriptions Resources

                                                            Zoho Projects Resources


                                                              Zoho Sprints Resources


                                                                Qntrl Resources


                                                                  Zoho Creator Resources


                                                                    Zoho WorkDrive Resources



                                                                      Zoho Campaigns Resources


                                                                        Zoho CRM Resources

                                                                        • CRM Community Learning Series

                                                                          CRM Community Learning Series


                                                                        • Tips

                                                                          Tips

                                                                        • Functions

                                                                          Functions

                                                                        • Meetups

                                                                          Meetups

                                                                        • Kbase

                                                                          Kbase

                                                                        • Resources

                                                                          Resources

                                                                        • Digest

                                                                          Digest

                                                                        • CRM Marketplace

                                                                          CRM Marketplace

                                                                        • MVP Corner

                                                                          MVP Corner





                                                                            Design. Discuss. Deliver.

                                                                            Create visually engaging stories with Zoho Show.

                                                                            Get Started Now