Once your workflow is published, you can call it from within your application. A URL and cURL example are provided for calling the workflow.
Below are examples of how you could make the request from within your code base. If you have protected your workflow trigger with a Lleverage API Token, create one under Settings > API Tokens of the project that your workflow belongs to.
JavaScript JavaScript (stream) Python
Copy async function callWorkflow (workflowId , inputs) {
const apiUrl = `https://fo10d.lleverage.run/ ${ workflowId } ` ;
const apiKey = "your-api-token" ;
const response = await fetch (apiUrl , {
method : "POST" ,
headers : {
"Content-Type" : "application/json" ,
Authorization : `Bearer ${ apiKey } ` ,
} ,
body : JSON .stringify (inputs) ,
});
if ( ! response .ok) {
throw new Error ( `Workflow call failed: ${ response .statusText } ` );
}
const responseText = await response .text ();
try {
return JSON .parse (responseText);
} catch (error) {
return responseText;
}
}
// Example usage:
const workflowId = "996c2fwy" ;
const inputs = {
subject : "Why Silicon deserves a seventh season." ,
targetAudience : "Boomers" ,
specificRequirements : "no spoilers" ,
};
callWorkflow (workflowId , inputs)
.then ((result) => console .log (result))
.catch ((error) => console .error ( "Error:" , error));
Copy async function callWorkflow (workflowId , inputs , onChunk) {
const apiUrl = `https://fo10d.lleverage.run/ ${ workflowId } ` ;
const apiKey = "your-api-token" ;
const response = await fetch (apiUrl , {
method : "POST" ,
headers : {
"Content-Type" : "application/json" ,
Authorization : `Bearer ${ apiKey } ` ,
} ,
body : JSON .stringify (inputs) ,
});
if ( ! response .ok) {
throw new Error ( `Workflow call failed: ${ response .statusText } ` );
}
const reader = response . body .getReader ();
const decoder = new TextDecoder ( "utf-8" );
let fullResponse = "" ;
while ( true ) {
const { done , value } = await reader .read ();
if (done) {
break ;
}
const chunk = decoder .decode (value);
fullResponse += chunk;
onChunk (chunk);
}
try {
return JSON .parse (fullResponse);
} catch (error) {
return fullResponse;
}
}
// Example usage:
const workflowId = "996c2fwy" ;
const inputs = {
subject : "Why Silicon deserves a seventh season." ,
targetAudience : "Boomers" ,
specificRequirements : "no spoilers" ,
};
callWorkflow (workflowId , inputs , (chunk) => {
console .log ( "Received chunk:" , chunk);
})
.then ((result) => console .log ( "Final result:" , result))
.catch ((error) => console .error ( "Error:" , error));
Copy import urllib . request
import json
import os
def call_workflow ( workflow_id , inputs ):
url = f "https://fo10d.lleverage.run/ { workflow_id } "
api_key = "your-api-token"
headers = {
"Content-Type" : "application/json" ,
"Authorization" : f "Bearer { api_key } "
}
data = json . dumps (inputs). encode ( 'utf-8' )
req = urllib . request . Request (url, data, headers, method = "POST" )
try :
with urllib . request . urlopen (req) as response :
response_text = response . read (). decode ( 'utf-8' )
return json . loads (response_text)
except urllib . error . HTTPError as e :
raise Exception ( f "Workflow call failed: { e.reason } " )
except json . JSONDecodeError :
return response_text
# Example usage:
workflow_id = "996c2fwy"
inputs = {
"subject" : "Why Silicon deserves a seventh season." ,
"targetAudience" : "Boomers" ,
"specificRequirements" : "No spoilers" ,
}
try :
result = call_workflow (workflow_id, inputs)
print (result)
except Exception as error :
print ( "Error:" , str (error))