# /organizations/{organizationId}/subaccounts/{subaccountId}/memberships/{membershipId}/personalAccessTokens

Create a new Personal Access Token for a subaccount user. The membership must have an accepted user (not an invitation).

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Partner API",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://admin.formstack.com/api/v1",
      "description": "Partner API"
    }
  ],
  "paths": {
    "/organizations/{organizationId}/subaccounts/{subaccountId}/memberships/{membershipId}/personalAccessTokens": {
      "post": {
        "tags": [
          "PartnerApi"
        ],
        "description": "Create a new Personal Access Token for a subaccount user. The membership must have an accepted user (not an invitation).",
        "operationId": "createSubaccountMembershipPersonalAccessToken",
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "description": "ID of the parent organization",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "example": "b443d63c-3e37-11f1-8898-0242ac000003"
            }
          },
          {
            "name": "subaccountId",
            "in": "path",
            "description": "ID of the subaccount",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "example": "8ecb0a3c-3e38-11f1-96c0-0242ac000003"
            }
          },
          {
            "name": "membershipId",
            "in": "path",
            "description": "ID of the membership (subaccount user)",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "example": "2b609bb4-3e57-11f1-8a46-0242ac000003"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePersonalAccessTokenRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Personal Access Token created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/common.PersonalAccessToken"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Organization, subaccount, or membership not found"
          },
          "422": {
            "description": "Validation error (e.g. invitation has no user, max keys reached)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/general_validation_error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "common.PersonalAccessToken": {
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true,
            "example": "2b609bb4-3e57-11f1-8a46-0242ac000003"
          },
          "name": {
            "type": "string",
            "example": "CI deploy key"
          },
          "secret": {
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "fs_pat_********"
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "example": "Read-only for billing exports"
          },
          "duration": {
            "writeOnly": true,
            "example": "90 days",
            "enum": [
              "30 days",
              "60 days",
              "90 days"
            ]
          },
          "expiresAt": {
            "description": "Y-m-d\\TH:i:sP format",
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "2019-09-01T12:35:30+00:00"
          },
          "createdAt": {
            "type": "string",
            "format": "date",
            "readOnly": true,
            "example": "2022-11-14T17:00:50-05:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date",
            "readOnly": true,
            "example": "2022-11-14T17:00:50-05:00"
          },
          "createdBy": {
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "user@example.com"
          },
          "updatedBy": {
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "user@example.com"
          },
          "revokedBy": {
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "user@example.com"
          },
          "owner": {
            "type": [
              "string",
              "null"
            ],
            "readOnly": true,
            "example": "John Doe"
          },
          "ownerMembershipId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "readOnly": true,
            "example": "2b609bb4-3e57-11f1-8a46-0242ac000003"
          },
          "status": {
            "description": "status of the key",
            "type": "string",
            "readOnly": true,
            "example": "active",
            "enum": [
              "active",
              "revoked",
              "expired"
            ]
          }
        },
        "type": "object"
      },
      "general_validation_error": {
        "properties": {
          "message": {
            "description": "Basic error description",
            "type": "string",
            "example": "The given data failed to pass validation."
          },
          "errors": {
            "description": "Basic error description",
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string",
                "example": "cannot be blank"
              }
            }
          }
        },
        "type": "object"
      },
      "CreatePersonalAccessTokenRequest": {
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "description": "Display name for the token",
            "type": "string",
            "example": "HawkSoft integration"
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "example": "Used for member sync in production"
          },
          "duration": {
            "type": [
              "string",
              "null"
            ],
            "example": "90 days",
            "enum": [
              "30 days",
              "60 days",
              "90 days"
            ]
          },
          "skipNotifications": {
            "description": "When true, do not queue PAT created email notifications.",
            "type": [
              "boolean",
              "null"
            ],
            "example": false
          }
        },
        "type": "object"
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer authentication"
      }
    }
  },
  "tags": [
    {
      "name": "PartnerApi",
      "description": "PartnerApi"
    }
  ]
}
```