API Reference

Complete reference of all Xano SDK methods organized by category.

Core Methods

XanoScript.create

Create a new endpoint builder.

ParameterTypeDescription
namestringEndpoint name (e.g., ‘users/list’)
methodstringHTTP method (GET, POST, PUT, DELETE, PATCH)
const endpoint = XanoScript.create('products/list', 'GET')

.description

Add endpoint description.

ParameterTypeDescription
textstringDescription text
.description('List all products with pagination')

.requiresAuth

Require authentication for this endpoint.

ParameterTypeDescription
tablestringUser table name (without quotes)
.requiresAuth('users')

Input Methods

.input

Define an input parameter.

ParameterTypeDescription
namestringInput parameter name
typestringData type (text, int, bool, email, password, object, json, decimal, timestamp)
optionsobjectOptions: required, default
.input('email', 'email', { required: true })
.input('page', 'int', { default: 1 })
.input('data', 'object')

Database Methods

.dbGet

Get a single record by field value.

ParameterTypeDescription
tablestringTable name (quoted)
filtersobjectSingle field filter
aliasstringVariable name to store result
.dbGet('"users"', { id: '$input.user_id' }, 'user')

.dbQuery

Query multiple records with advanced options.

ParameterTypeDescription
tablestringTable name (quoted)
optionsobjectQuery options (filters, pagination, sort, search)
aliasstringVariable name to store results
.dbQuery('"products"', {
  search: '$input.search',
  filters: { status: 'active' },
  pagination: { page: '$input.page', per_page: 20 },
  sort: { field: 'created_at', direction: 'desc' }
}, 'results')

.dbAdd

Create a new record.

ParameterTypeDescription
tablestringTable name (quoted)
dataobjectRecord data
aliasstringVariable name to store created record
.dbAdd('"users"', {
  email: '$input.email',
  first_name: '$input.first_name',
  created_at: 'now'
}, 'new_user')

.dbEdit

Update existing records.

ParameterTypeDescription
tablestringTable name (quoted)
filtersobjectFilter to match records
dataobjectUpdated data
aliasstringVariable name to store updated record
.dbEdit('"users"', 
  { id: '$auth.id' },
  { last_login: 'now' },
  'updated_user'
)

.dbDelete

Delete records.

ParameterTypeDescription
tablestringTable name (quoted)
filtersobjectFilter to match records
aliasstringVariable name to store deleted count
.dbDelete('"sessions"', { user_id: '$auth.id' }, 'deleted_count')

.dbBulkAdd

Add multiple records in one operation.

ParameterTypeDescription
tablestringTable name (quoted)
itemsstringVariable containing array of records
optionsobjectOptions: allowIdField
aliasstringVariable name to store created records
.dbBulkAdd('"products"', '$input.products', {
  allowIdField: true
}, 'created')

.dbBulkUpdate

Update multiple records.

ParameterTypeDescription
tablestringTable name (quoted)
itemsstringVariable containing array of records with ids
aliasstringVariable name to store updated count
.dbBulkUpdate('"products"', '$input.updates', 'updated_count')

.dbBulkDelete

Delete multiple records matching a condition.

ParameterTypeDescription
tablestringTable name (quoted)
searchConditionstringSearch condition expression
aliasstringVariable name to store deleted count
.dbBulkDelete('"sessions"', 'expires_at < now()', 'deleted_count')

Security Methods

.hashPassword

Hash a password securely.

ParameterTypeDescription
inputstringPlain text password
aliasstringVariable name to store hash
.hashPassword('$input.password', 'password_hash')

.verifyPassword

Verify a password against a hash.

ParameterTypeDescription
inputstringPlain text password
hashstringStored password hash
aliasstringVariable name to store boolean result
.verifyPassword('$input.password', '$user.password', 'is_valid')

.createToken

Generate a JWT token.

ParameterTypeDescription
payloadobjectData to embed in token
expirynumberTime to live in seconds
aliasstringVariable name to store token
.createToken({
  user_id: '$user.id',
  role: '$user.role'
}, 86400, 'auth_token')

.verifyToken

Verify a JWT token.

ParameterTypeDescription
tokenstringToken to verify
aliasstringVariable name to store verification result
.verifyToken('$input.token', 'token_data')

.createUuid

Generate a unique identifier.

ParameterTypeDescription
aliasstringVariable name to store UUID
.createUuid('transaction_id')

.randomNumber

Generate a random number.

ParameterTypeDescription
minnumberMinimum value (inclusive)
maxnumberMaximum value (inclusive)
aliasstringVariable name to store result
.randomNumber(100000, 999999, 'verification_code')

API Methods

.apiRequest

Make an HTTP request to an external API.

ParameterTypeDescription
urlstringAPI endpoint URL
methodstringHTTP method (GET, POST, PUT, DELETE, PATCH)
optionsobjectRequest options (headers, params, body, timeout)
aliasstringVariable name to store response
.apiRequest(
  'https://api.example.com/data',
  'POST',
  {
    headers: [
      { key: 'Authorization', value: 'Bearer $api_key' },
      { key: 'Content-Type', value: 'application/json' }
    ],
    body: { data: '$input.data' }
  },
  'api_response'
)

.graphqlRequest

Make a GraphQL query.

ParameterTypeDescription
urlstringGraphQL endpoint URL
querystringGraphQL query string
variablesobjectQuery variables
headersarrayRequest headers
aliasstringVariable name to store response
.graphqlRequest(
  'https://api.example.com/graphql',
  'query GetUser($id: ID!) { user(id: $id) { name email } }',
  { id: '$input.user_id' },
  [{ key: 'Authorization', value: 'Bearer $token' }],
  'graphql_response'
)

.lambda

Execute JavaScript code.

ParameterTypeDescription
codestringJavaScript code to execute
timeoutnumberTimeout in seconds
aliasstringVariable name to store result
.lambda(`
  const total = data.items.reduce((sum, item) => sum + item.price, 0);
  return { total: total };
`, 10, 'calculation')

Storage Methods

.createImage

Upload and store an image.

ParameterTypeDescription
accessstringAccess level (‘public’ or ‘private’)
valuestringImage data
filenamestringFilename to save as
aliasstringVariable name to store file info
optionsobjectProcessing options (resize, quality, format)
.createImage(
  'public',
  '$input.photo',
  'profiles/$auth.id.jpg',
  'uploaded_image',
  {
    resize: { width: 800, height: 600, fit: 'cover' },
    quality: 85
  }
)

.createVideo

Upload and store a video.

ParameterTypeDescription
accessstringAccess level (‘public’ or ‘private’)
valuestringVideo data
filenamestringFilename to save as
aliasstringVariable name to store file info
optionsobjectProcessing options
.createVideo(
  'private',
  '$input.video',
  'videos/$auth.id.mp4',
  'uploaded_video'
)

.createAttachment

Upload and store a document or file.

ParameterTypeDescription
accessstringAccess level (‘public’ or ‘private’)
valuestringFile data
filenamestringFilename to save as
aliasstringVariable name to store file info
.createAttachment(
  'private',
  '$input.document',
  'documents/$auth.id/$timestamp.pdf',
  'uploaded_doc'
)

.deleteFile

Delete a stored file.

ParameterTypeDescription
fileIdstringFile ID to delete
aliasstringVariable name to store deletion result
.deleteFile('$user.profile_photo_id', 'deleted')

Control Flow Methods

.conditional

Start a conditional block.

ParameterTypeDescription
conditionstringBoolean expression
.conditional('$user.role == "admin"')
  .then()
  .var('has_access', 'bool', true)
.else()
  .var('has_access', 'bool', false)
.endConditional()

.precondition

Validate a condition and stop execution if false.

ParameterTypeDescription
conditionstringBoolean expression
errorMessagestringError message if condition fails
.precondition('$user != null', 'User not found')
.precondition('$input.amount > 0', 'Amount must be positive')

.forEach

Loop through an array.

ParameterTypeDescription
arraystringArray variable
itemAliasstringVariable name for current item
.forEach('$input.items', '$item')
  .var('total', 'int', '$total + $item.price')
.endForEach()

.for

Execute a loop a specific number of times.

ParameterTypeDescription
iterationsstringNumber of iterations
indexAliasstringVariable name for loop index
.for('10', '$i')
  .var('squared', 'int', '$i * $i')
.endFor()

.while

Execute a loop while a condition is true.

ParameterTypeDescription
conditionstringBoolean expression
.while('$counter < 10')
  .var('counter', 'int', '$counter + 1')
.endWhile()

Variable Methods

.var

Declare and assign a variable.

ParameterTypeDescription
namestringVariable name
typestringData type (text, int, bool, object, array, decimal)
valueanyVariable value
.var('total', 'decimal', '$price * $quantity')
.var('is_valid', 'bool', '$user != null && $user.active')
.var('config', 'object', { timeout: 5000, retries: 3 })

.filter

Apply text transformations.

ParameterTypeDescription
inputstringInput value
filtersarrayArray of filter names
aliasstringVariable name to store result
.filter('$input.email', ['trim', 'lower'], 'clean_email')
.filter('$input.name', ['trim', 'capitalize'], 'formatted_name')

Available filters: trim, lower, upper, capitalize, replace, substr

.arrayPush

Add an item to an array.

ParameterTypeDescription
arraystringArray variable
valueanyValue to add
.var('results', 'array', [])
.arrayPush('$results', '$item')

Response Methods

.response

Set the endpoint response.

ParameterTypeDescription
dataobjectResponse data
.response({
  user: '$user',
  token: '$auth_token',
  message: 'Login successful'
})

.return

Early return from a conditional block.

ParameterTypeDescription
valueanyValue to return
.conditional('$user == null')
  .then()
  .return({ error: 'Not found' })
.endConditional()

Build Method

.build

Build the endpoint and generate XanoScript.

Returns an object with:

  • script - Generated XanoScript code
  • metadata - Endpoint metadata
const endpoint = XanoScript.create('users/list', 'GET')
  .description('List users')
  .input('page', 'int', { default: 1 })
  .dbQuery('"users"', {
    pagination: { page: '$input.page', per_page: 20 }
  })
  .response({ users: '$results.items' })
  .build();
 
console.log(endpoint.script);

Next Steps