> ## Documentation Index
> Fetch the complete documentation index at: https://api-reference.hyperswitch.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Gateway Score

> Feed a transaction outcome back into the success-rate model. Call this after every transaction so the engine has accurate SR data for future routing decisions.

# Update Gateway Score

## Use case

Records the observed transaction outcome for a previously selected gateway so auth-rate analytics can learn from real payment results.

## Authentication

Protected. Send either `Authorization: Bearer <jwt_token>` or `x-api-key: <api_key>`. In sandbox, also send `x-feature: decision-engine`.

For local development, start with:

```bash theme={null}
export BASE_URL=http://localhost:8080
export AUTH_HEADER="Authorization: Bearer <jwt_token>"
# Sandbox only:
# export BASE_URL=https://sandbox.hyperswitch.io
# export FEATURE_HEADER="x-feature: decision-engine"
```

## Request

* Method and path: `POST /update-gateway-score`
* Parameters: none.
* Body: JSON body should include merchant/payment identity, selected gateway, status, and latency/outcome details expected by the score updater.

## Example

### Update gateway score

```bash theme={null}
curl --location "$BASE_URL/update-gateway-score" \
  --header "$AUTH_HEADER" \
  --header "Content-Type: application/json" \
  --data '{
  "merchantId": "merchant_demo",
  "paymentId": "pay_sr_001",
  "gateway": "stripe",
  "status": "success",
  "amount": 1000,
  "currency": "USD",
  "paymentMethodType": "CARD",
  "paymentMethod": "CREDIT",
  "authType": "THREE_DS",
  "latency": 120
}'
```

## Response

```json theme={null}
{
  "status": "success",
  "message": "gateway score updated"
}
```

## Notes

* Do not call this after `NTW_BASED_ROUTING` just to record the selected debit network; debit audit comes from `/decide-gateway` analytics.
* Call it after payment authorization completes, not before.

## Related

* [Decide Gateway](/decision-engine-api-reference/api-reference/endpoint/gateway-decision/decideGateway)
* [Analytics Gateway Scores](/decision-engine-api-reference/api-reference/endpoint/analytics/analyticsGatewayScores)
* [Update Gateway Score](/decision-engine-api-reference/api-reference/guides/feedback-scoring/update-gateway-score)


## OpenAPI

````yaml decision_engine_openapi-specs.json POST /update-gateway-score
openapi: 3.1.0
info:
  title: Decision Engine
  description: >-
    Open-source payment gateway routing service by Juspay. Selects the optimal
    payment processor for each transaction in real-time using success-rate
    scoring, rule-based routing, and elimination logic.


    ## Authentication


    This API supports two authentication methods:


    1. **JWT Bearer Token** - For dashboard/user sessions
       - Header: `Authorization: Bearer <jwt_token>`
       - Obtain via `/auth/login` endpoint

    2. **API Key** - For service-to-service/programmatic access
       - Header: `x-api-key: DE_<64_char_hex>`
       - Create via `/api-key/create` endpoint

    Protected endpoints require one of these authentication methods.
  version: 1.4.0
  contact:
    name: Juspay
    url: https://github.com/juspay/decision-engine
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
servers:
  - url: http://localhost:8080
    description: Local development
  - url: https://sandbox.hyperswitch.io
    description: 'Hyperswitch sandbox with x-feature: decision-engine'
security: []
tags:
  - name: Health
    description: Service liveness, readiness, and diagnostics
  - name: Auth
    description: Dashboard auth and merchant selection
  - name: API Keys
    description: Service-to-service API key management
  - name: Gateway Decision
    description: Core routing decision APIs
  - name: Score Feedback
    description: Feed transaction outcomes back to improve SR scoring
  - name: Merchant Account
    description: Merchant configuration management
  - name: Routing Rules
    description: Euclid declarative routing rules engine
  - name: Rule Configuration
    description: Service-level SR/elimination config
  - name: Config
    description: Routing key and dimension metadata
  - name: Analytics
    description: ClickHouse-backed analytics and audit reads
  - name: Compatibility
    description: Legacy compatibility routes
  - name: Connector Costs
  - name: Merchant Features
  - name: Autopilot
paths:
  /update-gateway-score:
    post:
      tags:
        - Score Feedback
      summary: Update gateway score
      description: >-
        Feed a transaction outcome back into the success-rate model. Call this
        after every transaction so the engine has accurate SR data for future
        routing decisions.


        A `CHARGED` status increases the gateway's SR; failure statuses
        (`AUTHENTICATION_FAILED`, `AUTHORIZATION_FAILED`, etc.) decrease it.
      operationId: updateGatewayScore
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateGatewayScoreRequest'
            example:
              merchantId: test_merchant
              gateway: stripe
              paymentId: pay_001
              status: CHARGED
              gatewayReferenceId: stripe_ref_001
              enforceDynamicRoutingFailure: false
      responses:
        '200':
          description: Score updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateScoreResponse'
              example:
                message: Score updated
                merchant_id: test_merchant
                gateway: stripe
                payment_id: pay_001
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  schemas:
    UpdateGatewayScoreRequest:
      type: object
      required:
        - merchantId
        - gateway
        - paymentId
        - status
      properties:
        merchantId:
          type: string
          example: test_merchant
        gateway:
          type: string
          example: stripe
        paymentId:
          type: string
          example: pay_001
        status:
          type: string
          enum:
            - CHARGED
            - AUTHENTICATION_FAILED
            - AUTHORIZATION_FAILED
            - JUSPAY_DECLINED
            - FAILURE
          example: CHARGED
        gatewayReferenceId:
          type: string
          example: stripe_ref_001
        enforceDynamicRoutingFailure:
          type: boolean
          default: false
    UpdateScoreResponse:
      type: object
      properties:
        message:
          type: string
        merchant_id:
          type: string
        gateway:
          type: string
        payment_id:
          type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token obtained from /auth/login
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key created via /api-key/create

````