To store data in Zoho CRM using Laravel and the Zoho CRM API, you'll need to follow these steps:

  1. Create a Zoho CRM Account and Obtain API Credentials:

    • If you don't have a Zoho CRM account, sign up for one at https://www.zoho.com/crm/.
    • Go to the Zoho Developer Console at https://api-console.zoho.com/.
    • Create a new Client under the "Self-client" section to obtain the Client ID and Client Secret. These credentials will be used to authenticate your requests.
  2. Set Up Laravel Project:

  3. Install Required Packages:

    • In your Laravel project, install the guzzlehttp/guzzle package to make HTTP requests to the Zoho CRM API:
    bash
    composer require guzzlehttp/guzzle
  4. Configure API Credentials:

    • Open your .env file in the Laravel project root and add the Zoho CRM API credentials:
    makefile
    ZOHO_CLIENT_ID=your_client_id ZOHO_CLIENT_SECRET=your_client_secret
  5. Create a Route and Controller:

    • Create a new route in routes/web.php to handle the data storage request and map it to a controller method.
    php
    // routes/web.php Route::post('/store-to-zoho-crm', 'ZohoCRMController@store');
    • Generate a new controller using the following command:
    bash
    php artisan make:controller ZohoCRMController
  6. Implement the Store Method:

    • Open the ZohoCRMController.php file located in app/Http/Controllers and implement the store method:
    php
    <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use GuzzleHttp\Client; class ZohoCRMController extends Controller { public function store(Request $request) { $client = new Client(); // Replace with your actual Zoho CRM API endpoint $url = 'https://www.zohoapis.com/crm/v2/your_module_name'; $data = [ // Your data to be stored in Zoho CRM 'data' => [ [ 'field_name' => 'value', // Add more fields as needed ], ], ]; $response = $client->post($url, [ 'headers' => [ 'Authorization' => 'Zoho-oauthtoken ' . env('ZOHO_ACCESS_TOKEN'), // You need to get an access token first ], 'json' => $data, ]); // Handle the response as needed $statusCode = $response->getStatusCode(); $responseData = $response->getBody()->getContents(); // Return response or redirect back with status return response()->json($responseData, $statusCode); } }
  7. Obtain Zoho CRM Access Token:

  8. Send Data to Zoho CRM:

    • With the access token, you can send data to Zoho CRM by making a POST request to the appropriate Zoho CRM API endpoint. Replace your_module_name in the $url variable with the name of the module where you want to store the data. Also, update the data array with the fields and values you want to store in Zoho CRM.

Remember to handle errors and validation as needed in your controller method. Test your implementation, and you should be able to store data in Zoho CRM using the Zoho CRM API with Laravel.

Have questions or queries?
Get in Touch