Salla Docs
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipments & Fulfillment APIs
  • Recurring Payments API
  • App Functions
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipments & Fulfillment APIs
  • Recurring Payments API
  • App Functions
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Salla - Opensource
Salla - Developers Community
  1. App Functions
  • Welcome 👋
  • What are App Functions?
  • Get Started
  • Supported Events
  • Testing
  • Responses
  • NodeJs Support
  • Merchants Events
    • Brand Events
    • Cart Events
    • Category Events
    • Communication Events
    • Customer Events
    • Invoice Events
    • Review Events
    • Shipment Events
    • Shipping Company Events
    • Shipping Zone Events
    • Special Offer Events
    • Store Branch Events
  • Customers Events
    • Account Events
    • Cart & Checkout Events
    • Product Events
    • Promotion & Coupon Events
    • Wishlist Events
  1. App Functions

Get Started

Get started with App Functions in minutes. This guide walks you through creating your first App Function that responds to store events.

Prerequisites#

Before you begin, make sure you have:
✔️ Salla Partner Account — Sign up here if you don't have one
✔️ An App Created — Create an app in the Salla Partner Portal
✔️ Demo Store — Install your app on a demo store for testing
✔️ App Scopes — Configure the necessary scopes for the events you want to listen to

Setup Your Environment#

1. Configure App Scopes#

App scopes determine which events your app can access. To configure scopes:
1
Open Partner Portal
Navigate to your app in the Salla Partner Portal
2
Configure Scopes
Scroll down to the App Scopes section and select the scopes needed for your App Functions (e.g., orders.read, products.read)
3
Save Changes
Click Save to apply your scope configuration
App Scopes Configuration

2. Install on Demo Store#

To test your App Functions, install your app on a demo store:
1
Navigate to Your App
In the Partner Portal, open your app dashboard
2
Install on Demo Store
Click Install on Demo Store and select or create a demo store
3
Complete Installation
Follow the installation wizard to complete the process
Install on Demo Store
Learn more about testing with demo stores.

Understanding the Context Object#

Before creating your first function, it's important to understand what data your function receives.

How App Functions Work#

The Flow:
1.
⚡ Event Occurs — Merchant creates order, customer views product, etc.
2.
🔄 Salla Platform — Detects the event and finds your App Function
3.
📦 Context Object — Wraps event data (payload) + your app settings
4.
💻 Your Function — Receives context and executes your logic
5.
✔️ Response — Returns result (affects action for sync, ignored for async)

What You Receive#

Every App Function receives a context object with three main parts:

The Payload Object#

The payload contains the event data that Salla sends:
FieldTypeDescription
eventstringEvent name (e.g., order.created, product.updated)
merchantnumberMerchant ID who installed your app
created_atstringISO timestamp when the event occurred
dataobjectEvent-specific data (order, product, customer, etc.)
Example:
{
  "event": "order.created",
  "merchant": '123456',
  "created_at": "2024-03-24T10:30:00Z",
  "data": {
    "id": 789,
    "status": "pending",
    "total": 299.99
  }
}
The payload is diffrenet for each event/action, you can find the schema of each event/action in Merchants Events or Customers Events pages

The Settings Object#

The settings contains your app's configuration values that you define in the Partner Portal:
{
  "apiKey": "your-api-key",
  "webhookUrl": "https://api.example.com/webhook",
  "syncEnabled": true
}
Each merchant can customize these settings when they install your app.

Creating Your First App Function#

Let's create a simple App Function that listens to order status updates and sends data to an external webhook.

Step 1: Access the App Functions Editor#

1
Login to Partner Portal
Log in to your Salla Partner Portal
2
Open Your App
Navigate to the app you want to add the function to
3
Find App Functions Section
Scroll down to the App Functions section
4
Add New Function
Click Add New Function to open the editor
Add New Function
The App Function builder will appear with these sections:
🏷️ Function Name — Name your function
📋 Action Selector — Choose which event triggers your function
💻 Code Editor — Write your function logic
👁️ Preview Panel — Test and view results
App Function Builder

Step 2: Name Your Function#

Enter a descriptive name for your function that clearly indicates its purpose.
Example: order-status-webhook-notifier
Best Practices:
✔️ Use lowercase with hyphens
✔️ Be descriptive and specific
✔️ Include the event type and action

Step 3: Select an Action#

Click on the Select Action dropdown to see all available actions and events.
Action Selector
For this example, select Order Status Updated from the list.
Available Event Categories:
CategoryExamples
Orderscreated, updated, cancelled, refunded
Productsadded, updated, deleted, quantity low
Customerscreated, updated, login, OTP request
Shipmentscreating, created, cancelled, updated
And many more...brands, categories, coupons, reviews
Order Status Selected

Step 4: Write Your Function Code#

Once you select an action, the code editor updates with the function signature. Now you can write your custom logic.
Example Function: Send order status updates to a webhook
Key Points:
✔️ The function receives a context object with payload, settings and merchant objects
✔️ Use async/await for asynchronous operations
✔️ Always return a response object with success status

Step 5: Test Your Function#

Before deploying, test your function using the preview feature.
1
Select Demo Store
Click Select Store and choose your demo store
Select Store
2
Get Test Data
Navigate to your demo store dashboard and get test data (e.g., an Order ID)
Demo Store Dashboard
3
Enter Test Parameters
Enter the Order ID in the preview panel
Enter Order ID
4
Execute Function
Click Save and Preview to execute your function
Save and Preview
5
Review Results
Review the results in the preview panel:
✔️ Check for successful execution
✔️ Verify the response data
✔️ Look for any errors
✔️ If using a webhook testing service, verify the payload was received
Congratulations! You've successfully created your first App Function. 🎉

Accessing Salla APIs#

App Functions have built-in access to Salla APIs with automatic authentication:
Explore all available Salla APIs in the API Reference

Best Practices#

1. Keep Functions Focused#

Each function should do one thing well. If you need complex logic, break it into multiple functions or queue the remining impratant jobs

2. Return Consistent Responses#

Always return Response object with .success or .setError. You can find all the information about handling responses in 🤝 Understanding App Function Responses

3. Use Settings for Configuration#

Store API keys, URLs, and feature flags in app settings, not in code.

4. Log Important Information#

Use console.log() for debugging, but avoid logging sensitive data.

5. Test Thoroughly#

Test your functions with various scenarios:
✔️ Successful operations
✔️ Failed operations
✔️ Edge cases (null values, empty arrays)
✔️ Different data types

Publishing Your App Functions#

After creating and testing your App Functions:
1
Return to Partner Portal
Navigate to the Salla Partner Portal
2
Open Your App
Go to your app dashboard
3
Publish Changes
Click Publish to make your changes live
4
Notify Merchants
Merchants who have installed your app will receive the updates automatically
Sandbox vs Production: Changes are saved in the sandbox environment until you publish. Always test thoroughly before publishing.

Event Types Quick Reference#

Understanding when to use synchronous vs asynchronous events:
Asynchronous Events
Synchronous Actions
Comparison

Asynchronous Events Lifecycle#

When to use: Notifications, logging, syncing data, analytics, tracking
Works for: Both merchant actions and customer interactions
Characteristics:
✔️ Queued instantly (< 1 second) - user never waits
✔️ Runs in background after action completes
✔️ Doesn't block user experience
✔️ Function can take up to 30 seconds to execute
✔️ Return value doesn't affect the original action
Example Events:
Example Use Cases:

Next Steps#

Now that you've created your first App Function, explore more advanced features:
📋 Supported Events — See all available merchant and customer events
🧪 Testing App Functions — Learn advanced testing techniques
📚 Salla APIs — Explore Salla API documentation

Need Help?#

📖 Documentation — Browse complete documentation
👤 Partner Portal — Access your developer dashboard
👥 Community — Join our developer community
Modified at 2025-11-17 11:41:06
Previous
What are App Functions?
Next
Supported Events