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

# Update a feature credits entry

> #### This API let's you to update the following attributes: `effectiveUntil` and `granted`

- **effectiveUntil**: must be in future
- **granted**: must be greater than the existing usage (previous granted - current balance)


<AccordionGroup>
  <Accordion title="Example: Increase grantedUnits">
    **Initial**:

    ```
    {
      "id": "<entry_id>",
      "source": PURCHASE",
      "accountId": "acc.fdjsl.313",
      "featureId": "feat.fdjsl.313",
      "granted": 100,
      "balance": 20
    }
    ```

    **Action**: Update granted units to 120 units

    **POST** `/accounts/acc.fdjsl.313/features/feat.fdjsl.313/entries/<entry_id>`

    ```
    {
      "grantedUnits": 120
    }
    ```

    **Output**

    Adjustment units = new granted units - previous granted units  $(120 - 100 = 20)$

    New balance = current balance + adjustment units $(20 + 20 = 40)$
  </Accordion>

  <Accordion title="Example: Reduce grantedUnits">
    **Initial**:

    ```
    {
      "id": "<entry_id>",
      "source": PURCHASE",
      "accountId": "acc.fdjsl.313",
      "featureId": "feat.fdjsl.313",
      "granted": 100,
      "balance": 20
    }
    ```

    **Action**: Update granted units to 70 units

    **POST** `/accounts/acc.fdjsl.313/features/feat.fdjsl.313/entries/<entry_id>`

    ```
    {
      "granted": 70
    }
    ```

    **Output**

    Adjustment units = new granted units - previous granted units  $(70 - 100 = -30)$

    New balance = current balance + adjustment units $(20 + (-30) = -10)$ -> **`400 Bad Request`**
  </Accordion>
</AccordionGroup>


## OpenAPI

````yaml patch /accounts/{account_id}/features/{feature_id}/entries/{entry_id}
openapi: 3.0.3
info:
  version: '1.0'
  title: Togai Apis
  contact:
    email: engg@togai.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  description: APIs for Togai App
servers:
  - description: Api endpoint
    url: https://api.togai.com/
  - description: Sandbox api endpoint
    url: https://sandbox-api.togai.com/
security:
  - bearerAuth: []
tags:
  - name: Customers
    description: Customer level calls
  - name: Accounts
    description: Account level calls
  - name: Event Schemas
    description: Event Schema level calls
  - name: Usage Meters
    description: Usage Meter level calls
  - name: Price Plans
    description: (DEPRECATED) Price Plan level calls
  - name: PricePlanV2
    description: Price Plan V2 level calls
  - name: Schedules
    description: Account Schedule level calls
  - name: Pricing Rules
    description: Pricing Rules level calls
  - name: Settings
    description: Settings
  - name: Price Experimentation
    description: Price Experimentation apis
  - name: InvoiceGroups
    description: Invoice Group level calls
  - name: Organization
    description: Organization level calls
  - name: FileStorage
    description: File Storage level calls
  - name: Aliases
    description: Alias level calls
  - name: Reports
    description: Report level calls
  - name: ReportTemplates
    description: Report Template level calls
  - name: Customer Portal
    description: Portal level calls
  - name: Alerts
    description: Alert level calls
  - name: Event Management
    description: APIs for getting events ingested in Togai
    externalDocs:
      description: docs
      url: https://togai.com/docs/billing/events
  - name: Metrics
    description: APIs for getting Togai metrics
    externalDocs:
      description: docs
      url: https://togai.com/docs/metrics
  - name: Licenses
    description: APIs for getting or updating license records in Togai
  - name: Entitlements
    description: APIs related to entitlements
  - name: Invoices
    description: Invoices API
  - name: Credits
    description: Credits API
  - name: Wallet
    description: Wallet API
  - name: InvoiceTemplates
    description: InvoiceTemplates API
  - name: InvoiceSequence
    description: InvoiceSequence API
  - name: Payments
    description: Payments API
  - name: Authentication
    description: Authentication API
externalDocs:
  description: Find out more about Togai
  url: https://docs.togai.com/docs
paths:
  /accounts/{account_id}/features/{feature_id}/entries/{entry_id}:
    patch:
      tags:
        - Entitlements
      summary: Update a feature credits entry
      description: >
        #### This API let's you to update the following attributes:
        `effectiveUntil` and `granted`


        - **effectiveUntil**: must be in future

        - **granted**: must be greater than the existing usage (previous granted
        - current balance)
      operationId: UpdateFeatureCreditEntry
      parameters:
        - $ref: '#/components/parameters/account_id'
        - $ref: '#/components/parameters/feature_id'
        - $ref: '#/components/parameters/entry_id'
      requestBody:
        $ref: '#/components/requestBodies/UpdateFeatureCreditsRequest'
      responses:
        '200':
          description: Success response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeatureCreditEntry'
              examples:
                FeatureCreditEntry:
                  $ref: '#/components/examples/FeatureCreditEntry'
        '400':
          description: Bad request. Please check the response message for failure details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: >-
            Credential is not valid. Please check the response message for
            failure details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Credential does not have access to update a feature credit entry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: >-
            Entry not found. Please check the response message for failure
            details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Request throttled. Please check the response message on the failure
            details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  parameters:
    account_id:
      in: path
      description: account_id corresponding to an account
      name: account_id
      required: true
      schema:
        type: string
        maxLength: 50
        example: ACC00001
    feature_id:
      in: path
      description: feature_id corresponding to a feature
      name: feature_id
      required: true
      schema:
        type: string
        maxLength: 50
        example: feat.fdjskl.sdkjl
    entry_id:
      in: path
      description: >
        `entryId` corresponding to a particular entitlement/overage grant entry


        Formats:

        1. If source of entry is an entitlement grant rate card in price plan:
        `schedule_id#pricing_cycle_start_date$PRICE_PLAN`

        2. If source of entry is an entitlement overage rate card in price plan:
        `schedule_id#pricing_cycle_start_date$OVERAGE`

        3. If source of entry is a purchase: `purchase_id#int_index$PURCHASE`
      name: entry_id
      required: true
      schema:
        type: string
        maxLength: 50
        example: purchase.21HbazIT3JQ.D90jC#1$PURCHASE
  requestBodies:
    UpdateFeatureCreditsRequest:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UpdateFeatureCreditsRequest'
          examples:
            UpdateFeatureCreditsRequest:
              value:
                effectiveUntil: '2023-02-23T14:25:10Z'
                granted: 200
  schemas:
    FeatureCreditEntry:
      description: Get feature credits response
      type: object
      additionalProperties: false
      required:
        - id
        - source
        - status
        - used
        - effectiveFrom
        - effectiveUntil
      properties:
        id:
          type: string
          maxLength: 50
          example: purchase.20rvWRxQcQK.0ZwPG$1
        source:
          type: string
          description: Source of the feature credit
          enum:
            - ENTITLEMENT
            - PRICE_PLAN
            - OVERAGE
            - REFUND
        status:
          type: string
          description: Status of the feature credit entry
          enum:
            - ACTIVE
            - EXPIRED
            - VOIDED
        effectiveFrom:
          type: string
          format: date-time
          example: '2021-03-04T14:25:10Z'
        effectiveUntil:
          type: string
          format: date-time
          example: '2021-05-20T01:00:10Z'
        granted:
          type: number
          example: 15
        balance:
          type: number
          example: 10
        used:
          type: number
          example: 10
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - message
      properties:
        message:
          type: string
          description: error description
          maxLength: 500
    UpdateFeatureCreditsRequest:
      type: object
      properties:
        effectiveUntil:
          type: string
          format: date-time
          description: Expiry date-time for a feature credits entry
        granted:
          type: number
          description: Granted units for a feature credits entry
  examples:
    FeatureCreditEntry:
      summary: example update feature credits response
      value:
        id: purchase.20rvWRxQcQK.0ZwPG$1
        status: ACTIVE
        source: ENTITLEMENT
        effectiveFrom: '2020-01-01T00:00:00Z'
        effectiveUntil: '2025-01-01T00:00:00Z'
        granted: 15
        balance: 10
        used: 5
  responses:
    ErrorResponse:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            ErrorResponse:
              summary: Error message
              value:
                message: <Reason message>
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Bearer <credential>

````