Suger Code
Execute JavaScript code dynamically.
Suger Code will execute the JavaScript code when running the workflow.

There are many Suger APIs available that can be called in the code. Type $
in the code editor to get the auto-complete suggestions.

Marketplace API
query
Execute a query on Suger's internal database. You can only access data under the organization you are executing the workflow.
Parameters
query string: The query to execute.
Return format
object array: The result of the query. It's an array of objects, each object is a row in the query result.
Example
const offers = $marketplaceApi.query("select * from workload.offer");
return [{ json: offers }];
http
Send an HTTP request to Suger's REST API.
Parameters
- path string: The path to send the request to.
- method string: The method to send the request with.
- options object: The options for the request.
- body string: The body of the request.
- reader
binary | json
: The reader to read the body with. - additionalHeaders
{ [key: string]: string }
: The additional headers to send with the request. - fileName string: The file name to save the response to.
Return format
string: The response body.
Example
Create a contact using POST request.
return $marketplaceApi.http("contact", "post", {
body: JSON.stringify({ name: "John Doe", emailAddress: "john@suger.io" }),
});
Get a contact using GET request.
return $marketplaceApi.http("contact/id_of_the_contact", "get");
getOrganization
Get the organization you are executing the workflow for.
Parameters
None.
Return format
object: The organization.
Example
const organization = $marketplaceApi.getOrganization();
return { organization };
getProduct
Get a product by ID.
Parameters
- id string: The ID of the product.
Return format
object: The product.
Example
const product = $marketplaceApi.getProduct("id_of_the_product");
return { product };
listProducts
List all products.
Parameters
None.
Return format
object array: The list of products.
Example
const products = $marketplaceApi.listProducts();
return { products: products };
listProductsByPartner
List all products by partner.
Parameters
- partner string: The partner to list products for, available partners are AWS, AZURE, GCP.
Return format
object array: The list of products.
Example
const products = $marketplaceApi.listProductsByPartner("AWS");
return { products: products };
getOffer
Get an offer by ID.
Parameters
- id string: The ID of the offer.