---
agentTools:
  projectIndex: https://onebrick.readme.io/llms.txt
---

# [B2C Client] Regenerate API Key

Regenerates the API key for a given subaccount. The old key pair will be invalidated. Only B2C account with owner role can regenerate API key.

## Request Header

[block:parameters]
{
  "data": {
    "h-0": "Key Parameters",
    "h-1": "Data Type",
    "h-2": "Description",
    "0-0": "publicAccessToken",
    "0-1": "String",
    "0-2": "One time access-token generated using [this API](/reference/generate-public-access-token-jwt-token)",
    "1-0": "X-Signature",
    "1-1": "String",
    "1-2": "A HMAC-SHA512 signature generated using your API secret. This is used to verify the integrity and authenticity of the request. The signature is created based on the request payload and the X-Timestamp.",
    "2-0": "X-Timestamp",
    "2-1": "DateTime",
    "2-2": "The timestamp of the request in ISO 8601 format. This is used to validate the freshness of the request. Format: `YYYY-MM-DDTHH:MM:SS.SSS±HH:MM`  \nExample: `2025-05-27T10:17:54.964+07:00`"
  },
  "cols": 3,
  "rows": 3,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

## Request path parameters

| Key Parameters | Data Type | Description                                                                    |
| :------------- | :-------- | :----------------------------------------------------------------------------- |
| subAccountCode | String    | A unique alphanumeric code (max. 5 characters) used to identify the subaccount |

## Response parameters

| Key Parameters | Data Type | Description                                            |
| :------------- | :-------- | :----------------------------------------------------- |
| apiKey         | Object    | Object containing the generated API credentials        |
| clientKey      | String    | Encrypted public API key for the subaccount            |
| clientSecret   | String    | Encrypted secret key used to authenticate API requests |

## Error Response

Please check the [B2C Subaccount Onboarding Product Documentation](/reference/b2c-subaccount-onboarding-api-overview) for the error response

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Payment v2 General",
    "version": "2"
  },
  "servers": [
    {
      "url": "https://sandbox.onebrick.io/v2/payments/general"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "in": "header",
        "name": "publicAccessToken",
        "x-default": "Bearer"
      },
      "sec1": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Signature"
      },
      "sec2": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Timestamp"
      }
    }
  },
  "security": [
    {
      "sec0": [],
      "sec1": [],
      "sec2": []
    }
  ],
  "paths": {
    "/b2c/sub-accounts/{subAccountCode}/regenerate-api-key": {
      "post": {
        "summary": "[B2C Client] Regenerate API Key",
        "description": "Regenerates the API key for a given subaccount. The old key pair will be invalidated. Only B2C account with owner role can regenerate API key.",
        "operationId": "b2c-client-regenerate-api-key",
        "parameters": [
          {
            "name": "subAccountCode",
            "in": "path",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n  \"status\": 200,\n  \"message\": \"API keys regenerated successfully\",\n  \"data\": {\n    \"apiKey\": {\n      \"clientKey\": \"encrypted_new_client_key_xxx\",\n      \"clientSecret\": \"encrypted_new_client_secret_xxx\"\n    }\n  }\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 200,
                      "default": 0
                    },
                    "message": {
                      "type": "string",
                      "example": "API keys regenerated successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "apiKey": {
                          "type": "object",
                          "properties": {
                            "clientKey": {
                              "type": "string",
                              "example": "encrypted_new_client_key_xxx"
                            },
                            "clientSecret": {
                              "type": "string",
                              "example": "encrypted_new_client_secret_xxx"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n  \"status\": 400,\n  \"error\": {\n    \"code\": \"invalid_input\",\n    \"message\": \"Request body is invalid or incomplete.\",\n    \"action\": \"Check required fields and data types in the request body.\",\n    \"reason\": \"Missing or malformed parameters.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  },
                  "Image Upload Too Large": {
                    "value": "{\n  \"status\": 400,\n  \"error\": {\n    \"code\": \"image_too_large\",\n    \"message\": \"Uploaded image exceeds the allowed size limit.\",\n    \"action\": \"Please upload an image file less than 2MB.\",\n    \"reason\": \"File size exceeds configured maximum.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string",
                              "example": "invalid_input"
                            },
                            "message": {
                              "type": "string",
                              "example": "Request body is invalid or incomplete."
                            },
                            "action": {
                              "type": "string",
                              "example": "Check required fields and data types in the request body."
                            },
                            "reason": {
                              "type": "string",
                              "example": "Missing or malformed parameters."
                            }
                          }
                        },
                        "metadata": {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "example": "API"
                            },
                            "entity": {
                              "type": "string",
                              "example": "Subaccount"
                            }
                          }
                        },
                        "data": {}
                      }
                    },
                    {
                      "title": "Image Upload Too Large",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string",
                              "example": "image_too_large"
                            },
                            "message": {
                              "type": "string",
                              "example": "Uploaded image exceeds the allowed size limit."
                            },
                            "action": {
                              "type": "string",
                              "example": "Please upload an image file less than 2MB."
                            },
                            "reason": {
                              "type": "string",
                              "example": "File size exceeds configured maximum."
                            }
                          }
                        },
                        "metadata": {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "example": "API"
                            },
                            "entity": {
                              "type": "string",
                              "example": "Subaccount"
                            }
                          }
                        },
                        "data": {}
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "examples": {
                  "Unauthorized": {
                    "value": "{\n  \"status\": 401,\n  \"error\": {\n    \"code\": \"unauthorized\",\n    \"message\": \"Authentication failed. Invalid or expired access token.\",\n    \"action\": \"Re-authenticate and retry with a valid token.\",\n    \"reason\": \"Bearer token is missing or invalid.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 401,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "unauthorized"
                        },
                        "message": {
                          "type": "string",
                          "example": "Authentication failed. Invalid or expired access token."
                        },
                        "action": {
                          "type": "string",
                          "example": "Re-authenticate and retry with a valid token."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Bearer token is missing or invalid."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "examples": {
                  "Forbidden": {
                    "value": "{\n  \"status\": 403,\n  \"error\": {\n    \"code\": \"forbidden\",\n    \"message\": \"You are not authorized to perform this action.\",\n    \"action\": \"Ensure your account has the correct permissions (B2C role: main).\",\n    \"reason\": \"Insufficient access scope or role.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 403,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "forbidden"
                        },
                        "message": {
                          "type": "string",
                          "example": "You are not authorized to perform this action."
                        },
                        "action": {
                          "type": "string",
                          "example": "Ensure your account has the correct permissions (B2C role: main)."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Insufficient access scope or role."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "examples": {
                  "Subaccount Not Found": {
                    "value": "{\n  \"status\": 404,\n  \"error\": {\n    \"code\": \"not_found\",\n    \"message\": \"The requested subaccount does not exist.\",\n    \"action\": \"Verify the sub_account_code and try again.\",\n    \"reason\": \"Subaccount not found in the database.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 404,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "not_found"
                        },
                        "message": {
                          "type": "string",
                          "example": "The requested subaccount does not exist."
                        },
                        "action": {
                          "type": "string",
                          "example": "Verify the sub_account_code and try again."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Subaccount not found in the database."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "examples": {
                  "Duplicate Subaccount Code": {
                    "value": "{\n  \"status\": 409,\n  \"error\": {\n    \"code\": \"duplicate_code\",\n    \"message\": \"Subaccount code is already registered.\",\n    \"action\": \"Use a unique sub_account_code.\",\n    \"reason\": \"Conflict with existing subaccount record.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 409,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "duplicate_code"
                        },
                        "message": {
                          "type": "string",
                          "example": "Subaccount code is already registered."
                        },
                        "action": {
                          "type": "string",
                          "example": "Use a unique sub_account_code."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Conflict with existing subaccount record."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "429",
            "content": {
              "application/json": {
                "examples": {
                  "Rate Limit Exceeded": {
                    "value": "{\n  \"status\": 429,\n  \"error\": {\n    \"code\": \"rate_limit_exceeded\",\n    \"message\": \"Too many requests. Please slow down.\",\n    \"action\": \"Retry after 60 seconds or contact support to increase limit.\",\n    \"reason\": \"Request limit exceeded for client.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 429,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "rate_limit_exceeded"
                        },
                        "message": {
                          "type": "string",
                          "example": "Too many requests. Please slow down."
                        },
                        "action": {
                          "type": "string",
                          "example": "Retry after 60 seconds or contact support to increase limit."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Request limit exceeded for client."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "500": {
            "description": "500",
            "content": {
              "application/json": {
                "examples": {
                  "Internal Server Error": {
                    "value": "{\n  \"status\": 500,\n  \"error\": {\n    \"code\": \"server_error\",\n    \"message\": \"Something went wrong on our side.\",\n    \"action\": \"Try again later or contact support if the issue persists.\",\n    \"reason\": \"Unexpected error in server process.\"\n  },\n  \"metadata\": {\n    \"source\": \"API\",\n    \"entity\": \"Subaccount\"\n  },\n  \"data\": null\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer",
                      "example": 500,
                      "default": 0
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "server_error"
                        },
                        "message": {
                          "type": "string",
                          "example": "Something went wrong on our side."
                        },
                        "action": {
                          "type": "string",
                          "example": "Try again later or contact support if the issue persists."
                        },
                        "reason": {
                          "type": "string",
                          "example": "Unexpected error in server process."
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "source": {
                          "type": "string",
                          "example": "API"
                        },
                        "entity": {
                          "type": "string",
                          "example": "Subaccount"
                        }
                      }
                    },
                    "data": {}
                  }
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true,
  "_id": "683956868e04fb00127cbe4d:682b0b87cd6f710030d19383"
}
```