Skip to main content
POST
/
api
/
quotations
/
{requestId}
/
generate
curl --request POST \
  --url https://api.ambiotec.com/api/quotations/12345/generate \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "extraData": {
      "price_service": 5000.00,
      "price_transport": 250.00
    }
  }'
{
  "success": true,
  "quotation": {
    "quotationId": 789,
    "requestId": 12345,
    "templateName": "standard-quotation-v2",
    "status": "DRAFT",
    "priceService": 5000.00,
    "priceTransport": 250.00,
    "driveFileId": "1abc123xyz",
    "driveWebViewLink": "https://docs.google.com/document/d/1abc123xyz/view",
    "googleDocUrl": "https://docs.google.com/document/d/1abc123xyz/edit",
    "professionalPdfUrl": "https://ambiotec-quotations.s3.amazonaws.com/quotations/12345/789-professional-20260303.pdf",
    "createdBy": 42,
    "createdAt": "2026-03-03T10:30:00Z",
    "metadata": {
      "dataset": {},
      "extraData": {
        "price_service": 5000,
        "price_transport": 250
      },
      "generatedAt": "2026-03-03T10:30:00Z",
      "professionalPdf": {
        "bucket": "ambiotec-quotations",
        "key": "quotations/12345/789-professional-20260303.pdf",
        "url": "https://ambiotec-quotations.s3.amazonaws.com/quotations/12345/789-professional-20260303.pdf",
        "template": "standard-quotation-v2",
        "generatedAt": "2026-03-03T10:30:00Z"
      }
    }
  }
}
Generates a new quotation document by rendering a template, uploading it to Google Drive, and creating a professional PDF. The quotation is initially created with a DRAFT status.

Path Parameters

requestId
integer
required
The ID of the service request to generate a quotation for

Body Parameters

extraData
object
Additional data to include in the quotation

Response

success
boolean
Indicates if the quotation was generated successfully
quotation
object
The generated quotation object (see List Quotations for full structure)
curl --request POST \
  --url https://api.ambiotec.com/api/quotations/12345/generate \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "extraData": {
      "price_service": 5000.00,
      "price_transport": 250.00
    }
  }'
{
  "success": true,
  "quotation": {
    "quotationId": 789,
    "requestId": 12345,
    "templateName": "standard-quotation-v2",
    "status": "DRAFT",
    "priceService": 5000.00,
    "priceTransport": 250.00,
    "driveFileId": "1abc123xyz",
    "driveWebViewLink": "https://docs.google.com/document/d/1abc123xyz/view",
    "googleDocUrl": "https://docs.google.com/document/d/1abc123xyz/edit",
    "professionalPdfUrl": "https://ambiotec-quotations.s3.amazonaws.com/quotations/12345/789-professional-20260303.pdf",
    "createdBy": 42,
    "createdAt": "2026-03-03T10:30:00Z",
    "metadata": {
      "dataset": {},
      "extraData": {
        "price_service": 5000,
        "price_transport": 250
      },
      "generatedAt": "2026-03-03T10:30:00Z",
      "professionalPdf": {
        "bucket": "ambiotec-quotations",
        "key": "quotations/12345/789-professional-20260303.pdf",
        "url": "https://ambiotec-quotations.s3.amazonaws.com/quotations/12345/789-professional-20260303.pdf",
        "template": "standard-quotation-v2",
        "generatedAt": "2026-03-03T10:30:00Z"
      }
    }
  }
}

Business Logic

Document Generation Flow

  1. Service Request Validation: Fetches the service request data using fn_get_service_requests() function
  2. Document Rendering: Generates a DOCX document using the quotation template with request data and extra data
  3. Google Drive Upload: Uploads the DOCX as a Google Doc to the configured quotations folder
  4. Database Record: Creates a quotation record with DRAFT status, including:
    • Pricing information (price_service, price_transport)
    • Google Drive file references
    • User who created it
    • Metadata with generation details
  5. Professional PDF: Attempts to generate an HTML-based professional PDF and upload to S3
  6. Transaction: All operations are wrapped in a database transaction. If any step fails, the Google Drive file is cleaned up

Pricing Calculations

  • priceService and priceTransport are stored as separate fields
  • Total quotation amount = priceService + priceTransport
  • Pricing can be updated later when finalizing the quotation

Document Sharing

  • The Google Doc is automatically shared with the user’s email (from req.user.usuario_correo)
  • Documents are stored in the configured GOOGLE_QUOTATIONS_FOLDER_ID
  • A professional PDF is generated immediately for preview purposes

Notes

  • The quotation must be finalized before being sent to the client
  • The Google Doc can be edited before finalization
  • The professional PDF is generated from an HTML template for better formatting
  • If PDF generation fails, the quotation is still created successfully
  • The endpoint also works as a nested route: /api/serviceRequests/:id/quotations/generate

Build docs developers (and LLMs) love