> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sagescreen.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Advance Pipedrive deal stage

> WP calls this endpoint for two stage-change events.

**Event: demo_complete**
Fired the first time a candidate views their demo results page.
`email` is the candidate's email (no WP user). If the demo_user
post has company and website data, those are included.
No stored Pipedrive IDs are passed (no WP user to look them up from).

**Event: trial_complete**
Fired when a council completes Stripe checkout to convert from trial
to paid. Looks up the council_admin user. Stored PD IDs are read
from user meta and council post meta and passed as top-level fields.




## OpenAPI

````yaml /openapi/private/specs/services/services-integrations.yml post /quote-sync
openapi: 3.1.0
info:
  title: SageScreen — Intake & Pipedrive Integrations
  version: 1.0.0
servers:
  - url: https://{domain}/wp-json/sagescreen/v1
    description: WordPress REST API
    variables:
      domain:
        default: sagescreen.app
security: []
tags:
  - name: Intake
    description: Sales intake item endpoints
  - name: Account Created
    description: |
      Find-or-create person, org, and deal in Pipedrive.
      Fired for four WP events:
      - Demo signup (candidate, no WP user)
      - Trial account created (council_admin, new council)
      - Paid account created (council_admin, new council)
      - Council user added (any role added to existing council)
  - name: Quote Sync
    description: |
      Advance the Pipedrive deal stage.
      Fired for two WP events:
      - Demo completed (candidate views results for first time)
      - Trial complete (council upgrades from trial to paid)
paths:
  /quote-sync:
    post:
      tags:
        - Quote Sync
      summary: Advance Pipedrive deal stage
      description: |
        WP calls this endpoint for two stage-change events.

        **Event: demo_complete**
        Fired the first time a candidate views their demo results page.
        `email` is the candidate's email (no WP user). If the demo_user
        post has company and website data, those are included.
        No stored Pipedrive IDs are passed (no WP user to look them up from).

        **Event: trial_complete**
        Fired when a council completes Stripe checkout to convert from trial
        to paid. Looks up the council_admin user. Stored PD IDs are read
        from user meta and council post meta and passed as top-level fields.
      operationId: quoteSync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QuoteSyncRequest'
            examples:
              demoComplete:
                summary: demo_complete — candidate views results
                value:
                  email: john@example.com
                  first_name: John
                  last_name: Doe
                  phone: 555-1234
                  company: ACME Corp
                  stage: demo_complete
                  deal_fields:
                    wp_website: https://acme.com
              demoCompleteMinimal:
                summary: demo_complete — no company or website data
                value:
                  email: anon@example.com
                  first_name: Anonymous
                  last_name: User
                  stage: demo_complete
              trialComplete:
                summary: trial_complete — council upgrades from trial to paid
                value:
                  email: admin@acme.com
                  first_name: Jane
                  last_name: Smith
                  company: ACME Corp
                  stage: trial_complete
                  pd_contact_id: 1234
                  pd_org_id: 4001
                  pd_deal_id: 5001
      responses:
        '200':
          description: Stage change result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QuoteSyncResponse'
              examples:
                success:
                  summary: Stage advanced
                  value:
                    ok: true
                    pd_contact_id: 1234
                    pd_org_id: 4001
                    pd_deal_id: 5001
                authFailure:
                  summary: Bad or missing secret
                  value:
                    ok: false
                    error: Unauthorized
      security:
        - doFunctionSecret: []
components:
  schemas:
    QuoteSyncRequest:
      type: object
      required:
        - email
        - first_name
        - stage
      properties:
        email:
          type: string
          format: email
          description: Primary lookup key for the Pipedrive person record
          examples:
            - john@example.com
        first_name:
          type: string
          examples:
            - John
        last_name:
          type: string
          examples:
            - Doe
        phone:
          type: string
          description: Included on demo_complete if available from the demo signup form
          examples:
            - 555-1234
        company:
          type: string
          description: |
            demo_complete: value of `company` field from the demo_user post.
            trial_complete: council name from `get_the_title($council_post_id)`.
          examples:
            - ACME Corp
        stage:
          type: string
          enum:
            - demo_complete
            - trial_complete
          description: Pipedrive deal stage to advance to
          examples:
            - demo_complete
        deal_fields:
          $ref: '#/components/schemas/DealFields'
          description: |
            demo_complete only: includes `wp_website` when the demo signup
            form had a URL. Omitted on trial_complete.
        pd_contact_id:
          type: integer
          description: |
            trial_complete only: stored Pipedrive person ID from
            `user_meta.pipedrive_contact_id` on the council_admin user.
            Omitted if not yet stored or on demo_complete.
          examples:
            - 1234
        pd_org_id:
          type: integer
          description: |
            trial_complete only: stored Pipedrive org ID from
            `post_meta.pipedrive_company_id` on the `ss_council` post.
          examples:
            - 4001
        pd_deal_id:
          type: integer
          description: |
            trial_complete only: stored Pipedrive deal ID from
            `post_meta.pipedrive_deal_id` on the `ss_council` post.
          examples:
            - 5001
    QuoteSyncResponse:
      type: object
      properties:
        ok:
          type: boolean
          description: |
            true on success. WP uses the same guard as account-created:
            checks `ok === true` AND `pd_contact_id` before persisting IDs.
          examples:
            - true
        pd_contact_id:
          type: integer
          description: Pipedrive person ID resolved during stage change
          examples:
            - 1234
        pd_org_id:
          type: integer
          description: Pipedrive org ID resolved during stage change
          examples:
            - 4001
        pd_deal_id:
          type: integer
          description: Pipedrive deal ID advanced to new stage
          examples:
            - 5001
        error:
          type: string
          description: Human-readable error when ok is false
          examples:
            - Unauthorized
    DealFields:
      type: object
      description: Custom Pipedrive deal fields.
      properties:
        wp_deal_type:
          type: string
          enum:
            - trial
            - paid
          description: |
            Deal type for new council accounts. Omitted for demo signups and
            user_added events (deal already exists for the council).
          examples:
            - trial
        wp_website:
          type: string
          format: uri
          description: |
            Website URL from demo user's signup form. Sent on demo_complete
            if the `url` field was provided during demo signup.
          examples:
            - https://acme.com
  securitySchemes:
    doFunctionSecret:
      type: apiKey
      in: query
      name: k
      description: |
        Secret key appended by WP as `?k=<secret>`.
        Account-created uses `ss_pipedrive_sync_secret`.
        Quote-sync uses `ss_pipedrive_quote_sync_secret`.

````