Magidoc

Cloud Endpoint API

A Cloud Endpoint exists to allow external services to integrate with your CoCore account. There are two modes of operation - GraphQL, where the endpoint runs a preconfigured GraphQL query, and Script, where the endpoint runs a script to generate the payload to return.

This allows for simple, but powerful, integrations with other services such as Make.com, where our existing adapters might not offer all of the controls required.

The structure of an Endpoint

#

    
  

The lifecycle of a request

#

When a service makes a request to a Cloud Endpoint, we load in the configured endpoint settings, and perform the following steps:

  1. Parse the path of the request to enable dynamic segments to be populated. For example, if the path is setup as /jobs/:jobId and a request populates the path correctly, then the jobId will be available in the parameters of the handler.
  2. If a preHandler script is present, run the preHandler to transform the request variables. This allows offering a different public API to the internal GraphQL schema, for compatibility with other systems.
  3. Run the main handler:
    • For GraphQL handlers, we either extract variables from the payload returned by a preHandler, or this involves merging all of the present variables: body <- query <- url params into a single structure that will be passed as the variables to the GraphQL schema.
    • For JS handlers, this involves running the JS module and returning the result.

Prehandler API

#

    
  

Like all of our scripting, the preHandler must export a function main() . This will be executed by our Javascript engine, and the return value merged into the Payload . If the return object has a key variables , then this will be used as the input for a GraphQL mode handler.

The following examples show a prehandler that maps an incoming request body into a format that can be used for a createJob mutation.

    
  
    
  

GraphQL mode

#

This is the simplest mode of operation. You only need to declare a GraphQL operation, and it will be run, returning the output data back to the caller. This supports both queries (getting data) and mutations (changing data).

A simple example, to load a list of Jobs is as follows. It takes a query of first to change the number of jobs returned, and defaults to 10.

    
  
    
  

JS mode

#

This allows more advanced behaviours, dropping immediately into our scripting engine. This can be used in combination with things such as our CoConnect product to interact directly with Devices over an API.