Create an API key

FlexFactor allows you to create API keys to authenticate and interact with FlexFactor API endpoints.


Request

Endpoints

EnvironmentHTTP MethodEndpoint
Sandbox testingPOSThttps://api-sandbox.flex-charge.com/v1/api-keys
Production environmentPOSThttps://api.flex-charge.com/v1/api-keys

Required Keys

ParameterDescription
bearer tokenThe authentication token returned by /oauth2/token.

Body

Field NameTypeRequiredDescription
midStringYesUnique identifier of the merchant you want to create credentials for.
nameStringYesA brief name or description for the API Key.
Regex: ^[^<>]*$.
typeString (Enum)YesThe type of API Key:

- secret: used for auth, must be kept secure.
- public: used for auth
- tokenization: used for tokenization




Response

Field Definitions

Field NameTypeDescription
idStringUnique identifier for the API Key.
midStringThe FlexFactor unique identifier of the account associated with the API Key.
nameStringThe name or description of the API Key.
typeString (Enum)The type of the API Key (secret ,public, tokenization).
valueStringThe actual value of the API Key .
scopesArray of StringsThe list of access scopes defined for the API Key.
created_atString (DateTime)The timestamp of when the API Key was created.
errorsArray of StringsAny errors encountered during the API Key creation process.


❗️

Security for secret keys

  • The value field of secret key is only visible upon creation. Store it securely, as it cannot be retrieved later.

Payload Examples

Request

cURL Request Example

curl --request POST \
     --url https://api-sandbox.flexfactor.com/v1/api-keys \
     --header 'Authorization: bearer {the token returned by /oauth2}' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '{
       "mid": "mid_123456",
       "name": "My API Key",
       "scopes": ["customers:read", "charges:read"],
       "type": "secret"
     }'


Response

JSON Example for a Successful Creation

{
   "type": "secret",
   "value": "sk_test_4eC39HqLyjWDarjtT1zdp7dc",
   "mid": "mid_123456",
   "name": "My API Key",
   "scopes": ["customers:read", "charges:read"],
   "created_at": "2024-11-16T12:00:00Z",
}

JSON Example for a Failed Creation

{
   "type": null,
   "value": null,
   "name": null,
   "scopes": null,
   "created_at": null,
   "errors": [
       "Invalid scope value.",
       "Missing required field: type."
   ]
}

Example for Handling Errors

  • Missing Fields: If required fields are missing, the API returns a 400 error with detailed messages.
  • Invalid Credentials: If the bearer token is invalid, the API returns a 401 error.
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "errors": [
    "Invalid scope value."
  ]
}
HTTP/1.1 401 Unauthorized
Content-Type: application/json

{
  "errors": [
    "Authentication failed. Invalid bearer token."
  ]
}