Pakk Documentation
More HelpSubmit TicketPakk.io
  • Docs Home
  • Pakk Explained in 2 Minutes
  • Account Setup
    • Brands
    • Shipping Methods
      • Restricting Shipping Methods
      • Shipping Calculations
    • Payment Methods
      • Stripe
      • Paypal
      • Paytriot
      • VivaWallet
    • Admin Panel
      • Beginner Tutorial Series
        • Part 1: Overview of the Main Menu and Auxiliary Functions
        • Part 2: Overview of the Main Menu and Entities in the Admin Panel
        • Part 3: Overview of Data Management Features: Sorting, Filtering, and Bulk Actions
        • Part 4: Warnings and Detail Views
        • Part 5: Auxiliary Functionality
      • List Views
        • List View FAQs
      • Troubleshooting
  • Suppliers and Purchasing
    • Purchase Orders
      • Item Types
      • Stock Receipts
      • Invoicing and Payment
    • Demand Planning
      • Approaching the Demand Planner
      • Data Sources
      • Concepts
      • The Maths Behind the Predictions
      • Order Screen
  • Customers and Sales
    • Leads
    • Orders
      • Order Sources
        • Telephone Orders
        • In-Person Sales
      • Item Types
      • Order Status
        • Committed
        • Invoiced/Cash Saled
        • Dispatched
        • Paid
      • Order FAQs
    • Sales
      • Limitations of Sales
      • Entering and Processing Sales
      • Invoicing
      • Cancellation, Returns, Credits and Refunds
    • Credit Management
      • Payment Methods and Flows
      • Credit Terms
      • Credit Management
      • Credit Control
    • Credits, Refunds, Returns and Replacements
      • Customer Credits
        • Raising a Credit
        • The Impact of a Credit
        • Using a Credit
        • Checking Your Logic
      • Returns
      • Common Scenarios
    • Help Desk
      • Tickets
      • Configuring your Help Desk
      • Ticket Creation
      • Ticket Management
    • Loyalty Program
      • Set up Your Loyalty Program
      • Activate Your Loyalty Program on Site(s)
      • Administer your Loyalty Program
      • Accounting Considerations
  • Accounting, Bookkeeping and Finance
    • Accounting Overview
    • Accountants Guide to Pakk
    • Journal Entries
    • Rounding
    • Period Locking
    • Reconciliations
      • Create a Reconciliation
      • Build the Reconciliation
      • Completing Reconciliations
    • Cost of Goods Sold (COGS)
    • Multi-Currency
      • Exchange Rates
  • Products and Inventory
    • Pricing
      • Base Price
      • Bulk Pricing
      • Pricing Schemes
      • Per-Site Pricing
      • Web Discounts
      • Discount Adjustment Lines
      • Composite Products
    • Stock Control
      • Batches
        • Reusing Batches
    • Custom Product Attributes
      • Attribute Types
      • Attribute Setup
      • Apply to Products
    • Stock Adjustments
      • Stock Valuation
      • Assembly Builds
    • Multi-Location
      • Setting Up Locations
      • Items, Batches and Locations
      • Moving Stock between Locations
      • Incoming Stock
      • Outgoing Stock
    • Gross Margin Calculation and Control
      • Set up Default Variable Cost Parameters and Target Margin
      • Overrides
      • Margin Calculations
  • Websites
    • Visual Style Guide
      • Logo
      • Colour
      • Typography
      • Header
      • Custom CSS
      • Imagery
      • Icons
    • Configuration and Customisation
      • Website Development
      • Navigation Menus
        • Menus
        • Slots
          • Aux Bar Menu
          • Main Menu
          • Footer Menu
    • Product Categorisation
      • Related Groups
      • Product Variants
        • Variant Axes
        • Custom Attributes
        • Variant Category
        • Category List Page
        • Variant Shell Page
      • Category Warnings
    • Filtering and Sorting
      • Sorting
      • Filtering
    • Content
      • FAQs
        • Setting up FAQs
        • Using FAQs Around Your Site
      • Pages
      • Posts
      • Forms
        • How Customer Forms Work
        • Advanced Customisation
        • Confirmations, Notifications and Form Submissions
        • Use Cases and Examples
      • Feature Blocks
      • Feed Posts
      • Videos
    • SEO
      • What you need to do
      • What you don't need to worry about
    • Google Services
      • Analytics
      • Merchant Centre and Shopping Feed
      • Search Console and Sitemap
      • Adwords
    • GDPR, Privacy and Cookies
      • GDPR
      • Cookies
    • Reviews
      • Merchant Reviews
        • Shopping Experience Reviews
      • Product Reviews
    • Checkout
      • New Customers
      • Invoice Options
      • Custom Checkout Questions
      • Signup Options
    • Passwordless Login
    • Webstore Features
    • Email Sending
  • Admin and Reporting
    • Document Storage
    • Email Sending and Receiving
      • Postmark Setup
    • PDFs and Printing
  • Data and Integrations
    • Using Pakk with Other Systems
      • Pakk Integrated to Legacy Stock System
    • Data Import and Export
      • Export
        • CSV Conventions
        • List Fields
      • Import
        • Referencing Other Records
        • Test then Commit
        • Advanced
        • Importing Images & Documents
      • Tips and Tricks
    • API
      • Integrations
      • API Keys
      • Authentication
      • Integration Data (Key-Value Store)
      • Exploring API Requests and Responses
      • API Structure
        • Utility Endpoints
        • Generic Entity API
        • RPC API
        • CSV API
        • Document API
    • Webhooks
      • Setting Up a Webhook
      • Configuring the Webhook
      • Webhook Signature Verification
      • Data Transformation
      • Testing the Webhook
      • Webhook Execution Log
  • Pakk Services
    • Fulfilled by Pakk (FBP)
      • Overview of the Integration
      • Configuration
      • The FBP Tab
      • Products
      • Orders
      • Purchase Orders/ASNs
      • List Views
    • PakkPay
      • How to Setup PakkPay
Powered by GitBook
On this page
  • Enable Data Transformation
  • Transformation Code
  • Aborting Webhook Execution
  • Tips
Export as PDF
  1. Data and Integrations
  2. Webhooks

Data Transformation

The Pakk webhooks framework enables advanced use cases with data transformation using Javascript code you write yourself.

PreviousWebhook Signature VerificationNextTesting the Webhook

Last updated 5 months ago

If you have control over the server code at the webhook endpoint, then the shape of the data being sent is less important as you will be able to parse and process the data as needed with your own server-side code.

However, when the webhook endpoint is outside of your control, for example, if it is part of a third-party SaaS application, you'll probably need the shape of the webhook data to conform to a specific model. In this case, you can use Pakk's 'webhook data transformation' functionality to sculpt the request body that is sent to the webhook.

Enable Data Transformation

Before you can run any data transformation code, you need to check 'Enable Transformation' on the webhook configuration screen. This will activate a code input box for the transformation code.

Transformation Code

Enter the Javascript code to be run over the data. You'll need to take the following into account:

  • There are limits to the complexity of the code and the compute time it can take up - if you start hitting these limits, you'll be able to see the errors on the Webhook log

  • The input data to your code is as a Javascript object data. This data object has one or two sub objects: newState (always present) and previousState (only present for updates). Each of these obejcts is the full JSON representation of the record.

  • The outut of your code should be a Javascript object with the same name, data

Aborting Webhook Execution

If the business logic in your transformation code needs to abort execution of the webhook for any reason, simple return 0, null or false.

Tips

For most use cases, the easist thing to do is probably edit the input data and return it. For example, seting the memo field on an order could be done like this:

data.newState.memo="Testing"; return data.newState;

Alternatively, if you only need to return a small subset of fields, for example, you only need to extract the customer's email address from an order, you could start with a blank data object, like this:

data={"email": data.newState.customer.email}; return data;

As always, you can view the shape of the input data in the regular API docs, or simply send test webhook requests to a testing service without any transformations to directly see the untransformed data shape.

Remember that any transformations you apply are also applied when you test the webhook, making development easy.

Sometimes you might need to take action depending on how a record has changed - this can be achieved by comparing the previous state to the new state. For example, you could determine if an order has just been dispatched by comparing the new status to the previous.

Your code is executed in the cloud in a sandboxed Deno environment (as opposed to Node). Deno is mostly similar to Node, but if you need to get into more advanced use cases, you'll need to consult the Deno documentation:

https://docs.deno.com
Write custom Javascript to transform data