• Register

key.create

Description

Create a single key object.  Please see Creating Objects for an overview of how the create method works.

If the apikey field is left blank, a key will be randomly generated according to the appropriate algorithm for that service.

If the status field is left blank, the default status will be determined based on moderation settings established in the dashboard API Settings.

Parameters

key

An key object, as described by the object.describe call.  If a field in the key object is ommitted, a default value will be used if possible.  If extra fields are passed, they will be ignored.

Response

An key object, as described by the object.describe call.  This is actual key that was created.

Examples

In this example, we'll create a new key for a particular user and service.  This is the minimal key.create call.  We will not bind this key to an application.

A Sample JSON-RPC Key Create Request

{
    "method": "key.create",
    "params": [
        {
            "apikey": "example_apikey",
            "service": {
                "service_key": "example_service_key" 
            },
            "member": {
                "username": "example_username" 
            } 
        } 
    ],
    "id": 1
}

The JSON-RPC Response

{
    "result": {
        "id": 339,
        "created": "2009-12-04T21:34:46Z",
        "updated": "2009-12-04T21:34:46Z",
        "service_key": "example_service_key",
        "apikey": "example_apikey",
        "username": "example_username",
        "status": "waiting",
        "rate_limit_ceiling": 0,
        "qps_limit_ceiling": 0,
        "rate_limit_exempt": false,
        "qps_limit_exempt": false,
        "required_referer": "",
        "secret": "",
        "limits": [
            {
                "period": "second",
                "source": "service",
                "ceiling": 2
            },
            {
                "period": "day",
                "source": "service",
                "ceiling": 5000
            }
        ],
        "object_type": "key"
    },
    "error": null,
    "id": 1
}

Permissions Required

The user who owns the key used to authenticate the key.create call must be a member of one of the following roles

  • Administrator
  • Program Manager
  • Community Manager

See authentication.

Errors

In addition to the standard json-rpc errors and authentication errors, key.create may also return these errors:

HTTP Status Code JSON-RPC Code Error Message Description
400 1000 Invalid Object The object could not be created because the object would be invalid.  See Validating Fields for details on the format of this error.
400 1001 Duplicate Object The object could not be created because an object already exists with the same identifier.
400 1002 Field "x" is required. The object could not be created because a required field was not specified.  A field marked false for optional was not specified.  The error object data will include the name of the missing field.
500 2001 Create Failed The object could not be created.  This is the error message of last resort for object creation and usually indicates a systems integration failure, invalid internal data, or a transient issue.  These errors are logged by Mashery.
403 4200 This operation is not allowed for the service specified The service specified does not allow key creation via the API.

Docs Navigation