FM BetterForms
BF Editorfmbetterforms.com
master
master
  • Introduction
  • 🏆Features
  • Getting Started
    • Welcome to FM BetterForms!
    • System Overview
    • Quick Tour of the BetterForms IDE
    • Phase 1: Setting Up Your Foundation
      • 1.1 Configure FileMaker Server
      • 1.2 Install BetterForms Helper File
      • 1.3 Add Your Server to BetterForms (IDE)
    • Phase 2: Building Your First Application
      • 2.1 Create an App (Site) in the IDE
      • 2.2 Create Your First Page (Intro to Page Builder)
      • 2.3 Understanding & Managing Environments (IDE)
      • 2.4 Adding Elements to Your Page
      • 2.5 Understanding Validation
      • 2.6 Adding Actions to Your Page
      • 2.7 Creating Your First List View
      • 2.8 Understanding Page Data Flow
      • 2.9 Creating Your First Hook
      • 2.10 Working with Data Tables (Coming Soon)
    • Phase 3: Understanding Core BetterForms Concepts
      • 3.1 Introduction to Hooks (and where to find them in the IDE)
      • 3.2 Running Your First Hook (Practical Example)
      • 3.3 Introduction to Actions & Action Scripts (IDE Context)
      • 3.4 Understanding the Data Model (and Page Data Model UI)
    • Phase 4: Common Customizations & Expanding Your App
      • 4.1 Adding & Configuring Buttons (Page Builder)
      • 4.2 Implementing Page Navigation (Actions & Site Navigation UI)
      • 4.3 Displaying Data in Tables (Page Builder & Element Config)
      • 4.4 Basic App Styling (Site Styling UI)
    • Phase 5: Mastering the BetterForms Environment & Advancing Your Skills
      • 5.1 Understanding & Managing Environments (In-Depth)
      • 5.2 Deep Dive: Page Configuration & Settings
        • Navigating the Page Builder Interface
        • Working with Page-Level Action Scripts
        • Configuring the Page Data Model
        • Page Integration Settings Explained
        • Managing Page Info & Other Settings
      • 5.3 Working with Global Scripts
      • 5.4 Managing App (Site) Settings & Navigation
      • 5.5 Exploring Further: What to Learn Next
    • Support & Resources
      • Getting Help
      • Learning JSON
  • Reference
    • Site Settings
      • Navigation
      • App Model
      • DOM Header Insertions
      • Global Named Actions
      • Site Structure
      • Slots / Code Injection
    • Page Settings
      • Data Model
      • Card / Window Modals
      • Validation
        • Custom Validators
      • Misc Page Settings
    • Page Elements
      • Copy of Site Structure
      • BetterForms Elements
        • Checkbox
        • Checklist
        • Cleave.js Input Masking
        • DateTime Picker
        • Google Address Autocomplete
        • Image Display Element
        • Input
        • Masked Input
        • Range Slider (noUiSlider)
        • Radios
        • Select
        • Advanced Select (selectEx)
        • TextArea
      • Common
        • Input
        • Button
        • Data Table
        • HTML
      • Grouping Elements
        • Tabs
        • Panel
        • accordion
        • accordion2
        • listrows
      • Uploading Files
        • dropzone
        • dropzone to S3
        • uploadCare
        • 🏗️Uppy File Upload Widget Integration with AWS S3
      • Misc Elements
        • Plain Text / Code Editor
        • signature
        • fullCalendar
        • rangeSlider
      • Payment Gateways
        • Authorize.net
        • PayPal
        • Stripe
      • Adding Custom Page Elements
    • Actions Processor
      • Named Actions (Action Scripts)
      • Actions
        • runUtilityHook
        • path
        • debounce
        • throttle
        • showAlert
        • showModal / hideModal
        • function
        • clipboard
        • cookie
        • setFocus
        • scrollTo
        • wait
        • emit
        • validate
        • channelJoinAnon
        • channelLeaveAnon
        • messageSend
        • messageSendAnonChannel
        • consoleError
        • showStripeCheckout
      • Authentication Actions
    • Script Hooks
      • Globals Variables
        • $$BF_Model
        • $$BF_App
        • $$BF_State
      • Keeping Keys Private
      • Reducing Payload Size
      • API Callback Endpoint
      • Common Hooks
      • Scoped Hooks
    • Users & Authentication
      • Managing User Accounts
      • Custom Login Pages
      • OAuth
    • Advanced Configuration
      • Custom Domains
    • BF Utility Functions
      • Example Usage
        • BF.i18n()
    • BF Error Codes
    • Messaging
      • Adding users to channels
      • Removing users from channels
      • Sending messages
      • Get connected users
      • Get active channels
    • Practices for File Downloads
    • BF Streaming Proxy
    • Updating the Helper File
    • Connection Trouble Shooting Guide
    • Software Testing Overview
    • JavaScript Libraries
    • FM BetterForms - Quality Assurance
    • Rollbacks and Version Control
    • BF Server Proxy
    • Setting up Auth0
    • Create an S3 Bucket on AWS
    • ApexCharts - Getting started
    • BF Enterprise Documentation
    • BetterForms Error Pages API
    • BF Streaming API
    • Creating a PWA
  • Usage Tips
    • Troubleshooting
      • Debugging
      • Frozen Actions Queue
      • Vue Variables
    • JavaScript Tips
      • Calling Named Actions from HTML Vue Events
      • Calculations
    • Hacking a Webpage
    • System Overview
    • Forms Processor
      • Form Types
      • HTML & VueJS
      • Styling and Design
    • Customizing and Styling
      • Custom CSS
      • Custom Components
        • Components Editor
        • Component Best Practices
      • Page Pre-loaders
      • Favicon
    • Design Patterns and Best Practices
      • Working with environments
      • Handling Data
      • Saving Data
      • Data Optimization
      • Business Logic
      • UI / UX
      • Debugging
      • Script Engine Optimization
    • Getting Started
    • Installation
  • Security
    • Authentication
    • Security White Paper
    • Firewalls
    • Technology Stack
  • Compatibility
Powered by GitBook
On this page
  • Endpoint
  • Uses:
  • Supported Request Types
  • Supported Methods (verbs)
  • Performance
  • Suggested Design Pattern and Notes
  • Api Best Practices
  • Processing Time
  • Use workflow processing queues when needed

Was this helpful?

  1. Reference
  2. Script Hooks

API Callback Endpoint

This hook gives the developer access to a universal API endpoint. This can be used for any external callbacks or as an endpoint serving data.

This service can act as a universal endpoint and service multiple content types. The default is JSON but this can also be changed to others (see below).

Endpoint

/api*

Uses:

  • Callback for integrating various services

  • Document download endpoint

  • App entry point for passing data when integrating from another system. Eg. A user clicks a link in your online e-commerce store and that link hits the BetterForms API callback. This action passes some data that launches the user cart session.

Supported Request Types

  • plain text

  • application/json

  • application/xml

  • text/json

  • text/* - any text content type including text/xml

Supported Methods (verbs)

  • GET

  • POST

  • PUT

  • PATCH

  • DELETE

The hook is passes all header, query and body data as well as the request type (located in $params.method)

Set the $response var to the data you want to be returned.

Set the $contentType var to one of the following to return that content type and set the correct headers for the outbound data.

$contentType values
Content Type

empty or null / unset or 'json'

JSON

'html'

returns $response as html with headers set accordingly

'text'

returns $response as plain text.

'xml'

returns $response as xml with headers set accordingly

Surfaced $vars
Description

empty or null / unset or 'json'

JSON

$payload

$data

returns $response as plain text.

$body

if method supports a body, this contains the serialized body string

$params

object containing header, method and query objects

$mehod

The method verb name

For versions >0.9.35, API responses are able to send headers and status code, as shown below.

Example

Set Variable [$headers ; Value: JSONElement ( "" ; ["Content-Type" ; "text/plain" ; JSONString]; ["Transfer-Encoding" ; "chunked" ; JSONString] )

Example

Set Variable [$statusCode ; Value: 418 ]

Support for headers and statusCode

In order to include $headers and $statusCode to your API response, there's a change that needs to be done to the API hook script on business file.

  • On your API callback hook script, find where $$BF_Payload is set, as shown in the image below.

  • Modify its value so it maches the following code, where data.headers and data.statusCode are added to the existing JSONSetElement statement.

payload = JSONSetElement ( $$BF_Payload;
["data.response" ; $response ; If ($contentType = "text" or $contentType = "html"  or $contentType = "xml" ; JSONString ; JSONObject )];
["data.contentType" ; $contentType ; JSONString ];
["data.headers" ; $headers ; JSONObject];
["data.statusCode" ; $statusCode ; JSONNumber ];
["log" ; $$BF_Log ; JSONString]
);

Performance

You can expect finite performance from this API handler. Initial tests show about 20 concurrent calls or about 1800 calls per minute can be consistently achieved. This is dependent on server performance also.

Suggested Design Pattern and Notes

If you are returning JSON, make sure $response is set to a `JSONObject` type. For XML, and other custom serialized responses you an set $response to the string you want to return.

Keeping your API handler scripts orderly is key to stability and ease of code maintenance. If your API is handling more than one simple task it is recommended you use the example multi-endpoint script structure.

The image below shows a best practice for structuring endpoints and allows for easy API versioning down the road.

The concern of each endpoint is generally not to do business logic but to gather required data and format the response suitable to be returned to your calling server.

Here the main common hook script BetterForms - onAPICallBack ... acts as a dispatcher for each version. The V1 Dispatcher script then parses out each /endpoint and dispatches accordingly. For future debugging the head of each script has a logging step also.

// Sample inbound request 

    "params": {
      "headers": {
        "accept": "*/*",
        "accept-encoding": "gzip, deflate",
        "cache-control": "no-cache",
        "connection": "keep-alive",
        "content-type": "application/json",
        "cookie": "PHPSESSID=kmr6khj4nlruspai6tfiv0fcf7",
        "host": "mycallingdomain.com",
        "myheaderkey": "12345HEADERKEY0000",
        "postman-token": "2630f738-8f01-49af-acc6-556437a4a23b",
        "user-agent": "PostmanRuntime/6.2.5",
        "x-forwarded-for": "99.254.153.139",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https",
        "x-region": "usw"
      },
      "method": "GET",
      "provider": "rest",
      "query": {
        "key1": "1",
        "key2": "2"
      }
    }
  }

Api Best Practices

Processing Time

Keep your script calls to a minimum run time if your script is expecting to have a lot of traffic and the process takes a long time. One common technique for long process times is to queue up the process and return the caller back a token or status of processing etc.

Use workflow processing queues when needed

If you have a process that for example sends out several emails with a generated report the calling server will probably time out. Instead queue up the work flow and return just the parts of the data that can be prepared quickly.

PreviousReducing Payload SizeNextCommon Hooks

Last updated 3 years ago

Was this helpful?

the standard BetterForms Payload body object see

Set the $headers var to set the correct headers for the outbound data. For further reference of HTTP response headers options, please refer to .

Set the $statusCode var to set the correct value for HTTP status code response. For further reference of HTTP response headers options, please refer to .

docs
docs
Payload Object