Docs
GraphQL

Executing Flows with GraphQL API

What is GraphQL?

GraphQL is an open-source data query and manipulation language developed by Facebook. It provides a more efficient, powerful, and flexible alternative to traditional REST APIs. GraphQL allows clients to define the structure of the data they need, enabling them to retrieve precisely the information they require with a single request.

GraphQL over REST

img_2.png

While REST APIs have been the industry standard for many years, they often suffer from over-fetching or under-fetching data, leading to inefficient data transfers and increased latency. GraphQL addresses these limitations by empowering clients to request only the data they need, reducing network overhead and improving performance.

Setting up

Automatic Docs

img_3.png The easies way to setup GraphQL Connection is to click the Connect bar and get the automated code for your project. Lamatic.ai also generate automatic API documentation for your project. You can access it by visiting the API Docs section.

Authentication with API Keys

To ensure secure access to our platform, Lamatic.ai employs API keys for authentication. When triggering flows via GraphQL, you'll need to include your API key in the request headers. This key serves as a unique identifier, granting you authorized access to our services while maintaining the integrity and confidentiality of your data.

Here's an example of how you can include the API key in your GraphQL request headers:

Authorization: Bearer your_api_key

By including the API key in the Authorization header, our platform can verify your identity and grant you access to trigger the desired flow.

Click Here to know how to get your own API Key

Triggering Flows with GraphQL

Lamatic.ai's GraphQL integration allows you to trigger your GenAI flows seamlessly using GraphQL queries. This approach provides a standardized and efficient way to interact with our platform, enabling you to execute your GenAI flows on-demand or as part of larger application flows.

Here's an example GraphQL query that demonstrates how you can trigger a flow:

const axios = require('axios');
 
const query = `
query ExecuteWorkflow(
$workflowId: String!
$prompt: String    
) {
executeWorkflow(
workflowId: $workflowId
payload: {
  prompt: $prompt
}
) {
    status
    result
}
}`;
 
 
const variables = {"workflowId":"your_workflow_id","prompt":"The excited car draws."};
 
const options = {
method: 'POST',
url: 'your_project_endpoint',
headers: {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
},
data: { query, variables }
};
 
axios(options)
.then(response => console.log(response.data))
.catch(error => console.error(error));
 

Output

The Structure output can be configured in the Schema of the Graphql Response node. The expected output will be as follows:

{
  // Expected Output as setuped in the Schema
}

In this example, the ExecuteWorkflow query is used to initiate a workflow execution. You'll need to provide the workflowId of the desired workflow and any required payload(Input Data) as part of the query variables.

Was this page useful?

Questions? We're here to help

Subscribe to updates