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.
Return format
object: The offer.
Example
const offer = $marketplaceApi.getOffer("id_of_the_offer");
return { offer };
listOffers
List offers.
Parameters
- limit number: The limit of the offers to list.
- offset number: The offset of the offers to list.
Return format
object array: The list of offers.
Example
const offers = $marketplaceApi.listOffers(10, 0);
return { offers: offers };
listOffersByPartner
List offers by partner.
Parameters
- partner string: The partner to list offers for, available partners are AWS, AZURE, GCP.
- limit number: The limit of the offers to list.
- offset number: The offset of the offers to list.
Return format
object array: The list of offers.
Example
const offers = $marketplaceApi.listOffersByPartner("AWS", 10, 0);
return { offers: offers };
listOffersByProduct
List offers by product.
Parameters
- productId string: The ID of the product.
- limit number: The limit of the offers to list.
- offset number: The offset of the offers to list.
Return format
object array: The list of offers.
Example
const offers = $marketplaceApi.listOffersByProduct("id_of_the_product", 10, 0);
return { offers: offers };
listOffersByContact
List offers by contact.
Parameters
- contactId string: The ID of the contact.
Return format
object[]: The list of offers.
Example
const offers = $marketplaceApi.listOffersByContact("id_of_the_contact");
return { offers: offers };
getEntitlement
Get an entitlement by ID.
Parameters
- id string: The ID of the entitlement.
Return format
object: The entitlement.
Example
const entitlement = $marketplaceApi.getEntitlement("id_of_the_entitlement");
return { entitlement };
listEntitlements
List entitlements.
Parameters
- limit number: The limit of the entitlements to list.
- offset number: The offset of the entitlements to list.
Return format
object[]: The list of entitlements.
Example
const entitlements = $marketplaceApi.listEntitlements(10, 0);
return { entitlements: entitlements };
listEntitlementsByPartner
List entitlements by partner.
Parameters
- partner string: The partner to list entitlements for, available partners are AWS, AZURE, GCP.
- limit number: The limit of the entitlements to list.
- offset number: The offset of the entitlements to list.
Return format
object[]: The list of entitlements.
Example
const entitlements = $marketplaceApi.listEntitlementsByPartner("AWS", 10, 0);
return { entitlements: entitlements };
listEntitlementsByProduct
List entitlements by product.
Parameters
- productId string: The ID of the product.
- limit number: The limit of the entitlements to list.
- offset number: The offset of the entitlements to list.
Return format
object[]: The list of entitlements.
Example
const entitlements = $marketplaceApi.listEntitlementsByProduct(
"id_of_the_product",
10,
0
);
return { entitlements: entitlements };
listEntitlementsByBuyer
List entitlements by buyer.
Parameters
- buyerId string: The ID of the buyer.
Return format
object[]: The list of entitlements.
Example
const entitlements = $marketplaceApi.listEntitlementsByBuyer("id_of_the_buyer");
return { entitlements: entitlements };
listEntitlementsByOffer
List entitlements by offer.
Parameters
- offerId string: The ID of the offer.
Return format
object[]: The list of entitlements.
Example
const entitlements = $marketplaceApi.listEntitlementsByOffer("id_of_the_offer");
return { entitlements: entitlements };
getBuyer
Get a buyer by ID.
Parameters
- id string: The ID of the buyer.
Return format
object: The buyer.
Example
const buyer = $marketplaceApi.getBuyer("id_of_the_buyer");
return { buyer };
listBuyers
List all buyers.
Parameters
None.
Return format
object[]: The list of buyers.
Example
const buyers = $marketplaceApi.listBuyers();
return { buyers: buyers };
listBuyersByContact
List buyers by contact.
Parameters
- contactId string: The ID of the contact.
Return format
object[]: The list of buyers.
Example
const buyers = $marketplaceApi.listBuyersByContact("id_of_the_contact");
return { buyers: buyers };
listBuyersByPartner
List buyers by partner.
Parameters
- partner string: The partner to list buyers for, available partners are AWS, AZURE, GCP.
Return format
object[]: The list of buyers.
Example
const buyers = $marketplaceApi.listBuyersByPartner("AWS");
return { buyers: buyers };
getContact
Get a contact by ID.
Parameters
- id string: The ID of the contact.
Return format
object: The contact.
Example
const contact = $marketplaceApi.getContact("id_of_the_contact");
return { contact };
getContactsByIds
Get contacts by IDs.
Parameters
- contactIds string[]: The IDs of the contacts.
Return format
object[]: The list of contacts.
Example
const contacts = $marketplaceApi.getContactsByIds([
"id_of_the_contact1",
"id_of_the_contact2",
]);
return { contacts: contacts };