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

# Parse Contract Note PDF

> This endpoint parses Contract Note PDF files from various brokers including Zerodha, Groww, Upstox, ICICI Securities, and others.

**What is a Contract Note?**
A contract note is a legal document that provides details of all trades executed by an investor. It includes:
- Trade details with timestamps, quantities, and prices
- Brokerage and charges breakdown
- Settlement information
- Regulatory compliance details

**Supported Brokers:**
- Zerodha Broking Limited
- Groww Invest Tech Private Limited  
- Upstox (RKSV Securities)
- ICICI Securities Limited
- Auto-detection for unknown brokers

**Key Features:**
- **Auto-detection**: Automatically identifies broker type from PDF content
- **Comprehensive parsing**: Extracts equity transactions, derivatives transactions, detailed trades, and charges
- **Flexible input**: Accepts both file upload and URL-based PDF input
- **Password protection**: Supports password-protected PDFs

The API returns structured data including contract note information, client details, transaction summaries, and detailed trade-by-trade breakdowns.




## OpenAPI

````yaml /api-reference/openapi.yaml post /v4/contract_note/parse
openapi: 3.1.0
info:
  title: CAS Parser - Track Portfolios from CDSL, NSDL, CAMS, KFintech
  description: >-
    API for parsing and analyzing CAS (Consolidated Account Statement) PDF files
    from NSDL, CDSL, and CAMS/KFintech, with a unified response format
  version: 4.0.0
  contact:
    name: Sameer Kumar
    email: sameer@casparser.in
servers:
  - url: https://api.casparser.in
    description: Production server
  - url: https://portfolio-parser.api.casparser.in
    description: Legacy production server (still supported)
  - url: http://localhost:5000
    description: Local development server
security: []
tags:
  - name: CAS Parser
    description: Endpoints for parsing CAS PDF files from different sources.
  - name: CAS Generator
    description: Endpoints for generating new CAS documents via email mailback (KFintech).
  - name: CAS Fetch
    description: |
      Endpoints for fetching CAS documents with instant download.
      Currently supports CDSL via OTP authentication.
  - name: Email Import
    description: >
      Endpoints for importing CAS files directly from user email inboxes.


      **Supported Providers:** Gmail (more coming soon)


      **How it works:**

      1. Call `POST /v4/inbox/connect` to get an OAuth URL

      2. Redirect user to the OAuth URL for consent

      3. User is redirected back to your `redirect_uri` with an encrypted
      `inbox_token`

      4. Use the token to list/fetch CAS files from their inbox
      (`/v4/inbox/cas`)

      5. Files are uploaded to temporary cloud storage (URLs expire in 24 hours)


      **Security:**

      - Read-only access (we cannot send emails)

      - Tokens are encrypted with server-side secret

      - User can revoke access anytime via `/v4/inbox/disconnect`
  - name: Inbound Email
    description: >
      Create dedicated inbound email addresses for investors to forward their
      CAS statements.


      **Use Case:** Your app wants to collect CAS statements from users without
      requiring OAuth or file upload.


      **How it works:**

      1. Call `POST /v4/inbound-email` to create a unique inbound email address

      2. Display this email to your user: "Forward your CAS statement to
      ie_xxx@import.casparser.in"

      3. When user forwards a CAS email, we verify sender authenticity
      (SPF/DKIM) and call your webhook

      4. Your webhook receives email metadata + attachment download URLs


      **Sender Validation:**

      - Only emails from verified CAS authorities are processed:
        - CDSL: `eCAS@cdslstatement.com`
        - NSDL: `NSDL-CAS@nsdl.co.in`
        - CAMS: `donotreply@camsonline.com`
        - KFintech: `samfS@kfintech.com`
      - Emails failing SPF/DKIM/DMARC are rejected

      - Forwarded emails must contain the original sender in headers


      **Billing:** 0.2 credits per successfully processed valid email
  - name: Contract Note Parser
    description: >-
      Endpoints for parsing Contract Note PDF files from various SEBI brokers
      like Zerodha, Groww, Upstox, ICICI etc.
  - name: Authorization
    description: |
      Endpoints for checking API quota and credits usage.
      These endpoints help you monitor your API usage and remaining quota.
  - name: Portfolio Connect
    description: >
      Endpoints for managing access tokens for the Portfolio Connect SDK.

      Use these to generate short-lived `at_` prefixed tokens that can be safely
      passed to frontend applications.

      Access tokens can be used in place of API keys on all v4 endpoints.
  - name: Agent Auth
    description: >
      Endpoints for coding agents to obtain API keys via a browser-based
      approval flow.


      **How it works:**

      1. Agent generates a random token locally (e.g. `openssl rand -hex 32`).
      No API call needed.

      2. Agent asks the user to open
      `https://app.casparser.in/agent-auth?token=<token>&client_name=<name>`

      3. User signs in via the browser and clicks Approve.

      4. Agent polls `GET /v1/agent-auth/token/{token}` every 5 seconds until
      the key is delivered.


      **Security:**

      - Token must be 16-128 characters (recommended: 64 hex chars / 256 bits)

      - Approved keys are delivered once (one-shot) and then deleted

      - Tokens expire after 10 minutes if not approved
  - name: KYC
    description: >
      Endpoints for verifying KYC (Know Your Customer) status of Indian
      investors.


      **Data source:** CVL KRA public inquiry portal (cvlkra.com), which
      aggregates

      records from all five SEBI-registered KRAs: CVL, NDML, CAMS, Karvy, and
      KFin.


      **Status normalization:** Raw CVL portal strings are normalized into clean
      enums.

      See the `kyc_status` property on `KycPanStatusResponse` for the full list.


      **Credits:** 0.5 per successful lookup. Failed lookups are not billed.
paths:
  /v4/contract_note/parse:
    post:
      tags:
        - Contract Note Parser
      summary: Parse Contract Note PDF
      description: >
        This endpoint parses Contract Note PDF files from various brokers
        including Zerodha, Groww, Upstox, ICICI Securities, and others.


        **What is a Contract Note?**

        A contract note is a legal document that provides details of all trades
        executed by an investor. It includes:

        - Trade details with timestamps, quantities, and prices

        - Brokerage and charges breakdown

        - Settlement information

        - Regulatory compliance details


        **Supported Brokers:**

        - Zerodha Broking Limited

        - Groww Invest Tech Private Limited  

        - Upstox (RKSV Securities)

        - ICICI Securities Limited

        - Auto-detection for unknown brokers


        **Key Features:**

        - **Auto-detection**: Automatically identifies broker type from PDF
        content

        - **Comprehensive parsing**: Extracts equity transactions, derivatives
        transactions, detailed trades, and charges

        - **Flexible input**: Accepts both file upload and URL-based PDF input

        - **Password protection**: Supports password-protected PDFs


        The API returns structured data including contract note information,
        client details, transaction summaries, and detailed trade-by-trade
        breakdowns.
      operationId: parseContractNote
      requestBody:
        $ref: '#/components/requestBodies/ContractNoteParseRequest'
      responses:
        '200':
          description: Successfully parsed contract note
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  msg:
                    type: string
                    example: success
                  data:
                    $ref: '#/components/schemas/ContractNoteResponse'
        '400':
          $ref: '#/components/responses/ParseBadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - ApiKeyAuth: []
components:
  requestBodies:
    ContractNoteParseRequest:
      required: true
      content:
        multipart/form-data:
          schema:
            type: object
            properties:
              pdf_file:
                type: string
                format: binary
                description: Contract note PDF file to parse
              password:
                type: string
                description: Password for the PDF file (usually PAN number)
              broker_type:
                type: string
                description: Optional broker type override
                enum:
                  - zerodha
                  - groww
                  - upstox
                  - icici
            required:
              - pdf_file
              - password
        application/json:
          schema:
            type: object
            properties:
              pdf_file:
                type: string
                format: base64
                description: Base64 encoded contract note PDF file
                example: JVBERi0xLjQKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwo...
              pdf_url:
                type: string
                format: uri
                description: URL to the contract note PDF file
                example: https://example.com/contract_note.pdf
              password:
                type: string
                description: Password for the PDF file (usually PAN number for Zerodha)
                example: FAXAK2545F
              broker_type:
                type: string
                description: >-
                  Optional broker type override. If not provided, system will
                  auto-detect.
                enum:
                  - zerodha
                  - groww
                  - upstox
                  - icici
                example: zerodha
            oneOf:
              - required:
                  - pdf_file
                  - password
              - required:
                  - pdf_url
                  - password
  schemas:
    ContractNoteResponse:
      type: object
      properties:
        contract_note_info:
          type: object
          properties:
            contract_note_number:
              type: string
              description: Contract note reference number
              example: CNT-25/26-73436720
            trade_date:
              type: string
              format: date
              description: Date when trades were executed
              example: '2025-08-05'
            settlement_number:
              type: string
              description: Settlement reference number
              example: '2025149'
            settlement_date:
              type: string
              format: date
              description: Settlement date for the trades
              example: '2025-08-06'
        broker_info:
          type: object
          properties:
            broker_type:
              type: string
              description: Auto-detected or specified broker type
              enum:
                - zerodha
                - groww
                - upstox
                - icici
                - unknown
              example: zerodha
            name:
              type: string
              description: Broker company name
              example: Zerodha Broking Limited
            sebi_registration:
              type: string
              description: SEBI registration number of the broker
              example: INZ000031633
        client_info:
          type: object
          properties:
            name:
              type: string
              description: Client name
              example: VIRENDER KUMAR
            pan:
              type: string
              description: Client PAN number
              example: FAXAK2545F
            ucc:
              type: string
              description: Unique Client Code
              example: YS3654
            place_of_supply:
              type: string
              description: GST place of supply
              example: DELHI
            gst_state_code:
              type: string
              description: GST state code
              example: '7'
            address:
              type: string
              description: Client address
        equity_transactions:
          type: array
          description: Summary of equity transactions grouped by security
          items:
            type: object
            properties:
              isin:
                type: string
                description: ISIN code of the security
                example: INE172A01027
              security_name:
                type: string
                description: Name of the security
                example: CASTROLIND
              security_symbol:
                type: string
                description: Trading symbol
                example: CASTROLIND
              buy_quantity:
                type: number
                format: float
                description: Total quantity purchased
              buy_wap:
                type: number
                format: float
                description: Weighted Average Price for buy transactions
              buy_total_value:
                type: number
                format: float
                description: Total value of buy transactions
              sell_quantity:
                type: number
                format: float
                description: Total quantity sold
              sell_wap:
                type: number
                format: float
                description: Weighted Average Price for sell transactions
              sell_total_value:
                type: number
                format: float
                description: Total value of sell transactions
              net_obligation:
                type: number
                format: float
                description: Net amount payable/receivable for this security
        derivatives_transactions:
          type: array
          description: Summary of derivatives transactions
          items:
            type: object
            properties:
              contract_description:
                type: string
                description: Derivatives contract description
                example: NIFTY24802410DPE
              buy_sell_bf_cf:
                type: string
                description: Transaction type (Buy/Sell/Bring Forward/Carry Forward)
                example: B
              quantity:
                type: number
                format: float
                description: Quantity traded
              wap_per_unit:
                type: number
                format: float
                description: Weighted Average Price per unit
              brokerage_per_unit:
                type: number
                format: float
                description: Brokerage charged per unit
              closing_rate_per_unit:
                type: number
                format: float
                description: Closing rate per unit
              net_total:
                type: number
                format: float
                description: Net total amount
        detailed_trades:
          type: array
          description: Detailed breakdown of all individual trades
          items:
            type: object
            properties:
              order_number:
                type: string
                description: Order reference number
                example: '1000000042939390'
              order_time:
                type: string
                description: Time when order was placed
                example: '13:13:13'
              trade_number:
                type: string
                description: Trade reference number
                example: '4006567'
              trade_time:
                type: string
                description: Time when trade was executed
                example: '13:13:13'
              security_description:
                type: string
                description: Security name with exchange and ISIN
                example: CASTROLIND-EQ/INE172A01027
              buy_sell:
                type: string
                description: Transaction type (B for Buy, S for Sell)
                example: B
              exchange:
                type: string
                description: Exchange name
                example: NSE
              quantity:
                type: number
                format: float
                description: Quantity traded
              brokerage:
                type: number
                format: float
                description: Brokerage charged for this trade
              net_rate_per_unit:
                type: number
                format: float
                description: Net rate per unit
              closing_rate_per_unit:
                type: number
                format: float
                description: Closing rate per unit
              net_total:
                type: number
                format: float
                description: Net total for this trade
              remarks:
                type: string
                description: Additional remarks or notes
        charges_summary:
          type: object
          description: Breakdown of various charges and fees
          properties:
            pay_in_pay_out_obligation:
              type: number
              format: float
              description: Net pay-in/pay-out obligation
            taxable_value_brokerage:
              type: number
              format: float
              description: Taxable brokerage amount
            exchange_transaction_charges:
              type: number
              format: float
              description: Exchange transaction charges
            cgst:
              type: number
              format: float
              description: Central GST amount
            sgst:
              type: number
              format: float
              description: State GST amount
            igst:
              type: number
              format: float
              description: Integrated GST amount
            securities_transaction_tax:
              type: number
              format: float
              description: Securities Transaction Tax
            sebi_turnover_fees:
              type: number
              format: float
              description: SEBI turnover fees
            stamp_duty:
              type: number
              format: float
              description: Stamp duty charges
            net_amount_receivable_payable:
              type: number
              format: float
              description: Final net amount receivable or payable
    ErrorResponse:
      type: object
      required:
        - status
        - msg
      properties:
        status:
          type: string
          description: The status of the error.
          enum:
            - failed
          example: failed
        msg:
          type: string
          description: A descriptive message explaining the error.
          example: Invalid PDF file or password.
    AuthErrorResponse:
      type: object
      required:
        - status
        - msg
      properties:
        status:
          type: string
          description: The status of the error.
          example: error
        msg:
          type: string
          description: A descriptive message explaining the error.
          example: 'Authentication failed: API key is missing.'
  responses:
    ParseBadRequest:
      description: Bad request (Invalid PDF file, missing parameters, or invalid password)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Unauthorized. This can happen if the `x-api-key` header is missing.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthErrorResponse'
          example:
            status: error
            msg: >-
              Authentication failed: API key is missing. Please provide a valid
              API key in the x-api-key header.
    Forbidden:
      description: >-
        Forbidden. This can happen if the API key is invalid or the quota has
        been exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthErrorResponse'
          example:
            status: error
            msg: >-
              Authentication failed: API quota exceeded or invalid API key.
              Please check your API key or quota limits.
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: |
        Your API key for authentication.
        Use `sandbox-with-json-responses` as Sandbox key.

````