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>"
}
'import requests
url = "https://api-eu.flexportal.io/v1/files/contracts/generate"
payload = {
"orderId": "<string>",
"contractType": "<string>"
}
headers = {
"Tenant-ID": "<tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Tenant-ID': '<tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({orderId: '<string>', contractType: '<string>'})
};
fetch('https://api-eu.flexportal.io/v1/files/contracts/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-eu.flexportal.io/v1/files/contracts/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => '<string>',
'contractType' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Tenant-ID: <tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-eu.flexportal.io/v1/files/contracts/generate"
payload := strings.NewReader("{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Tenant-ID", "<tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-eu.flexportal.io/v1/files/contracts/generate")
.header("Tenant-ID", "<tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-eu.flexportal.io/v1/files/contracts/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Tenant-ID"] = '<tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"fileId": "<string>",
"orderId": "<string>",
"tenantId": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Files
Generate Contract
Generates a PDF contract for an order using tenant-configured templates.
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>"
}
'import requests
url = "https://api-eu.flexportal.io/v1/files/contracts/generate"
payload = {
"orderId": "<string>",
"contractType": "<string>"
}
headers = {
"Tenant-ID": "<tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Tenant-ID': '<tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({orderId: '<string>', contractType: '<string>'})
};
fetch('https://api-eu.flexportal.io/v1/files/contracts/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-eu.flexportal.io/v1/files/contracts/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => '<string>',
'contractType' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Tenant-ID: <tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-eu.flexportal.io/v1/files/contracts/generate"
payload := strings.NewReader("{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Tenant-ID", "<tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-eu.flexportal.io/v1/files/contracts/generate")
.header("Tenant-ID", "<tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-eu.flexportal.io/v1/files/contracts/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Tenant-ID"] = '<tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"<string>\",\n \"contractType\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"fileId": "<string>",
"orderId": "<string>",
"tenantId": "<string>"
}{
"error": {
"code": "<string>",
"message": "<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
| Field | Required | Description |
|---|---|---|
orderId | Yes | Order to generate contract for |
templateId | No | Custom 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
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 Code | Cause | Solution |
|---|---|---|
ORDER_NOT_FOUND | Invalid order ID | Verify order exists |
TEMPLATE_NOT_FOUND | Invalid template ID | Use valid template or omit for default |
Related Endpoints
- Get File - Get contract metadata
- Get File URL - Get download URL
- List Files - View all order documents
- Get Order - View order details
Authorizations
API key obtained from FlexPortal dashboard
Headers
Your tenant identifier
Was this page helpful?