Search code examples
suitecrm

Create Custom API V8 in Suite CRM


Good Day!

I am planning to create a custom API for Account module were I am going to get and update data using API. I created a custom field (integration_ref_id) on my Account module this will serve as my identifier if the accounts is existing or not. Check bellow as payload request sample

{
"consent_timestamp": "2021-04-13 09:45:00",
"integration_ref_id": "CUSREF-202104-ABCDEF0000003",
"last_name": "De la Cruz",
"first_name": "Juan",
"birthdate": "1995-03-25",
"mobile_number": "+639171234199",
"email": "[email protected]",
"location_code": "LOC0001",
"street_name": "Rose St.",
"landmarks": "Mcdo",
"gender": "male"
}

Now I created custom routes on my custom folder (custom/application/Ext/Api/V8/Config)

<?php
$app->get('/my-route/{myParam}', 'MyCustomController:myCustomAction');

$app->get('/hello', function() {
    return 'Hello World!';
});

$app->get('/getCustomers', 'Api\V8\Controllers\CustomersController:getCustomers');

And I place the controller same path of the routes. (custom/application/Ext/Api/V8/Controller)

And this is my controller code

<?php
namespace Api\V8\Controller;

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}



class CustomersController extends BaseController
{
    public function getCustomers(Request $request, Response $response, array $args, GetRelationshipParams $params)
    {
        try {
            $jsonResponse = $this->relationshipService->getCustomers($request);
            return $this->generateResponse($response, $jsonResponse, 200);
        } catch (\Exception $exception) {
            return $this->generateErrorResponse($response, $exception, 400);
        }
    }
}

But I got this Error in postman enter image description here

I keep searching, but its kinda confusing on my end. BTW I am new on this SuiteCRM

Regards!


Solution

  • Never mind, I was able to figure it out. I just added this code below to my controller CustomeController.php

    namespace Api\V8\Controller;
    use Slim\Http\Response;
    use Slim\Http\Request;
    

    And added this one to my custom controller.php

    require 'custom/application/Ext/Api/V8/Controller/CustomersController.php';
    use Api\V8\Controller;
    use Slim\Container;
    

    Then everything should be working.