Skip to main content
POST
/
v1
/
files
/
contracts
/
generate
Generate a contract
curl --request POST \
  --url https://api-eu.flexportal.io/v1/files/contracts/generate \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'Tenant-ID: <tenant-id>' \
  --data '
{
  "orderId": "<string>",
  "contractType": "<string>"
}
'
{
  "success": true,
  "message": "<string>",
  "fileId": "<string>",
  "orderId": "<string>",
  "tenantId": "<string>"
}

Overview

Generate a contract document for an order. Contracts are automatically populated with order details, customer information, and your tenant’s terms and branding.

Request Fields

FieldRequiredDescription
orderIdYesOrder to generate contract for
templateIdNoCustom template ID (uses default if not specified)

Example Request

{
  "orderId": "ord_abc123"
}

What Gets Generated

The contract includes:
  • Customer Information: Name, company, contact details
  • Order Details: Items, quantities, pricing
  • Billing Terms: Payment schedule, amounts
  • Contract Terms: Duration, conditions
  • Your Branding: Logo, company info from tenant settings

Response

{
  "success": true,
  "fileId": "file_contract_xyz789",
  "fileName": "contract-ord_abc123.pdf",
  "downloadUrl": "https://storage.example.com/...",
  "expiresAt": "2025-01-15T12:00:00Z"
}

Example: Generate and Attach to Order

async function createOrderContract(orderId) {
  // Generate the contract
  const { fileId, downloadUrl } = await generateContract({ orderId });

  // Contract is automatically linked to the order
  console.log(`Contract ${fileId} generated for order ${orderId}`);

  return {
    contractId: fileId,
    downloadUrl
  };
}

Contract Templates

Contracts use templates configured in your tenant settings:
  • Default Template: Standard contract layout
  • Custom Templates: Industry or use-case specific formats
Configure templates in Dashboard → Settings → Contract Templates.

Common Use Cases

  • Order Confirmation: Generate contract when order is confirmed
  • Customer Portal: Let customers download their contracts
  • Compliance: Maintain signed contract records
  • Automation: Auto-generate contracts on order creation

Example: Auto-Generate on Order Confirm

async function confirmOrderWithContract(orderId) {
  // Confirm the order
  await updateOrder(orderId, { status: 'confirmed' });

  // Generate contract
  const contract = await generateContract({ orderId });

  // Optionally email to customer
  await sendContractEmail(orderId, contract.downloadUrl);

  return {
    orderConfirmed: true,
    contractGenerated: true,
    contractId: contract.fileId
  };
}

Error Handling

Error CodeCauseSolution
ORDER_NOT_FOUNDInvalid order IDVerify order exists
TEMPLATE_NOT_FOUNDInvalid template IDUse valid template or omit for default

Authorizations

Authorization
string
header
required

API key obtained from FlexPortal dashboard

Headers

Tenant-ID
string
required

Your tenant identifier

Body

application/json
orderId
string
required
Minimum string length: 1
contractType
string

Response

Contract generated

success
enum<boolean>
required
Available options:
true,
false
message
string
required
fileId
string
required
orderId
string
required
tenantId
string
required