Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

swamydeshetty's avatar

Integration of zoho in laravel

Im trying to integrate the zoho in my laravel application im getting this issue [2024-10-09 11:06:19] local.INFO: Error fetching customers: {"status":401,"body":"{"code":57,"message":"You are not authorized to perform this operation"}","error":{"code":57,"message":"You are not authorized to perform this operation"}} why like this im getting im already generated the access token and the refresh token but stilll im getting this issue

0 likes
2 replies
jdc1898's avatar

I’m thinking you’re not authorized to make the request. 🤪

Check the permissions to make sure you can not just authenticate but also have permission to perform the action with the token provided.

swamydeshetty's avatar

im already authorized how can get the access token without authorization public function callback(Request $request) { // Step 1: Get the authorization code $code = $request->query('code');

    // Step 2: Exchange the authorization code for an access token
    $clientId = env('ZOHO_CLIENT_ID');
    $clientSecret = env('ZOHO_CLIENT_SECRET');
    $redirectUri = 'http://127.0.0.1:8000/auth/zoho/callback';  // Must match the redirect URI

    // Step 3: Make a POST request to get the access token
    $response = Http::asForm()->post('https://accounts.zoho.in/oauth/v2/token', [
        'grant_type' => 'authorization_code',
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'redirect_uri' => $redirectUri,
        'code' => $code,
    ]);

    // Log the entire response for debugging
    \info('Zoho Token Response', $response->json());

    // Step 4: Check if the response is successful
    if ($response->successful()) {
        info($request->all());
        $accessToken = $response->json()['access_token'];
        // $refreshToken = $response->json()['refresh_token'];

        // Store the access token and refresh token in the cache
        Cache::put('zoho_access_token', $accessToken, now()->addMinutes(55)); // Assuming the token is valid for 1 hour
        // Cache::put('zoho_refresh_token', $refreshToken, now()->addDays(30)); // Store refresh token for 30 days

        // Redirect or return a response
        return redirect('/')->with('success', 'Successfully authenticated with Zoho!');
    } else {
        // Log the error response
        // \error('Zoho Token Error', $response->json());

        // Handle error
        return redirect('/')->with('error', 'Failed to authenticate with Zoho. Check logs for details.');
    }
} my code to  authorization

Please or to participate in this conversation.