Hello devs!
I have installed Espo version 7.5.5 and set up a node JS implementation of API calls with HMAC authorisation as described here. I can now create leads, contacts, etc as well as custom entities defined in entity manager via the API. However I need to create a few entities in one API call, so I've written a custom module as described here.
In Custom\Espo\Modules\MyModule I have:
Api\MyAction
Controllers\MyController
Binding
MyService1
I'm using the Binding class to attach the MyService1 service to the container. The MyAction API is successfully calling the MyService1 where I am going to put the application logic. (I think this is the right way to do it)
I want the custom API to create a contact, then create a product registration record containing a Serial number and another ID and link the two records. I think I need to do something like what is described in CRUD actions:
(the above is pulled straight from the documentation but I was going to put this into my service class as I believe we are supposed to keep controllers lean).
My problem is how to tell postActionCreate what kind of record I want to create. I assume this method decides the record type from the the path section of the URL (eg /contact), but mine is a custom URL with something like ContactProductRegistration. Is there a way that I can tell the postActionCreate to create a contact and then call it again to create the custom product registration entity and then call something to link the two together, or do I need to do something more custom?
Many thanks,
Clare
I have installed Espo version 7.5.5 and set up a node JS implementation of API calls with HMAC authorisation as described here. I can now create leads, contacts, etc as well as custom entities defined in entity manager via the API. However I need to create a few entities in one API call, so I've written a custom module as described here.
In Custom\Espo\Modules\MyModule I have:
Api\MyAction
Controllers\MyController
Binding
MyService1
I'm using the Binding class to attach the MyService1 service to the container. The MyAction API is successfully calling the MyService1 where I am going to put the application logic. (I think this is the right way to do it)
I want the custom API to create a contact, then create a product registration record containing a Serial number and another ID and link the two records. I think I need to do something like what is described in CRUD actions:
PHP Code:
<?php
namespace Espo\Custom\Controllers;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
class MyController {
// Creates a record.
public function postActionCreate(Request $request, Response $response): void {}
}
My problem is how to tell postActionCreate what kind of record I want to create. I assume this method decides the record type from the the path section of the URL (eg /contact), but mine is a custom URL with something like ContactProductRegistration. Is there a way that I can tell the postActionCreate to create a contact and then call it again to create the custom product registration entity and then call something to link the two together, or do I need to do something more custom?
Many thanks,
Clare
Comment