Beanstalk

Public Key Resource

Public keys belong to Users and are used for Git authentication and deployments.

Readable attributes

id integer Unique ID of the PublicKey.
account_id integer ID of the associated Account.
user_id integer ID of the User who owns the key.
name string Human-readable name of the key.
content string Public SSH key.
updated_at datetime Time when the Invitation was last updated.
created_at datetime Time when the Invitation was first added to the system.

Writable attributes

name string Optional, will be derived from the content if possible or filled with a date stamp.
content string Required. Should contain a single public SSH key.

Permissions

It’s important to note that admins can list, update, create and delete keys for all users under account while regular users can only work with their own keys. If you are logged in as an admin and you want to create/update/delete key that belongs to another user from your account, just add a user_id parameter to the URL.

Find All Public Keys

Admins can pass user_id parameter to fetch keys for all account’s users. Otherwise only current user’s keys are returned.

json http-request
GET /api/public_keys.json
GET /api/public_keys.json?user_id={USER_ID}

Click to expand…

json http-response
[
  {
    "public_key": {
      "name": "Mac Pro",
      "created_at": "2011/07/29 22:56:13 +0800",
      "updated_at": "2011/07/29 22:56:13 +0800",
      "account_id": 2,
      "id": 2,
      "user_id": 2,
      "content": "ssh-rsa AAAA...hfs1Q=="
    }
  },{
    "public_key": {
      "name": "IBM PC Compatible",
      "created_at": "2011/07/29 22:56:13 +0800",
      "updated_at": "2011/07/29 22:56:13 +0800",
      "account_id": 2,
      "id": 4,
      "user_id": 2,
      "content": "ssh-rsa AAAA...fe4gQ=="
    }
  }
]
xml http-request
GET /api/public_keys.xml
GET /api/public_keys.xml?user_id={USER_ID}

Click to expand…

xml http-response
<?xml version="1.0" encoding="UTF-8"?>
<public-keys type="array">
  <public-key>
    <id type="integer">6</id>    
    <account-id type="integer">8</account-id>
    <user-id type="integer">5638</user-id>
    <name>ilya@MacBookPro.local</name>
    <content>
      ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
    </content>
    <created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
    <updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>    
  </public-key>
</public-keys>

Find Public Key

Admins can view other users’ keys. Regular users can view their own keys only.

json http-request
GET /api/public_keys/{PUBLIC_KEY_ID}.json

Click to expand…

json http-response
{
  "public_key": {
    "name": "Mac Pro",
    "created_at": "2011/07/29 22:56:13 +0800",
    "updated_at": "2011/07/29 22:56:13 +0800",
    "account_id": 2,
    "id": 2,
    "user_id": 2,
    "content": "ssh-rsa AAAA...hfs1Q=="
  }
}
xml http-request
GET /api/public_keys/{PUBLIC_KEY_ID}.xml

Click to expand…

xml http-response
<?xml version="1.0" encoding="UTF-8"?>
<public-key>
  <id type="integer">6</id>    
  <account-id type="integer">8</account-id>
  <user-id type="integer">5638</user-id>
  <name>ilya@MacBookPro.local</name>
  <content>
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
  </content>
  <created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
  <updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>    
</public-key>

Create Public Key

Admins can pass user_id parameter to create a key for a specific user under that account, otherwise the key will be created for a currently logged in user.

Name is optional and will be derived from the key if possible. Otherwise it will be stubbed with a date stamp.

json http-request
POST /api/public_keys.json
{
  "public_key": {
    "name": "Special Name",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q== ilya@MacBookPro.local"
  }
}

Click to expand…

json http-response
{
  "public_key": {
    "name": "Special Name",
    "created_at": "2011/07/29 22:56:13 +0800",
    "updated_at": "2011/07/29 22:56:13 +0800",
    "account_id": 2,
    "id": 2,
    "user_id": 2,
    "content": "ssh-rsa AAAA...fhfs1Q=="
  }
}
xml http-request
POST /api/public_keys.xml
<?xml version="1.0" encoding="UTF-8"?>
<public_key>
  <content>
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q== ilya@MacBookPro.local
  </content>
</public_key>

Click to expand…

xml http-response
<?xml version="1.0" encoding="UTF-8"?>
<public-key>
  <id type="integer">7</id>    
  <account-id type="integer">8</account-id>
  <user-id type="integer">5638</user-id>
  <name>ilya@MacBookPro.local</name>
  <content>
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
  </content>
  <created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
  <updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>    
</public-key>

--OR IF INVALID--

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>Content is not a valid public SSH key</error>
</errors>

Update Public Key

Admins can update other users’ keys. Regular users can update their own keys only.

json http-request
PUT /api/public_keys/{PUBLIC_KEY_ID}.json
{
  "public_key": {
    "name": "Awesome Key"
  }
}

Click to expand…

json http-response
{
  "public_key": {
    "name": "Awesome Key",
    "created_at": "2011/07/29 22:56:13 +0800",
    "updated_at": "2011/07/29 22:56:13 +0800",
    "account_id": 2,
    "id": 2,
    "user_id": 2,
    "content": "ssh-rsa AAAA...hfs1Q=="
  }
}
xml http-request
PUT /api/public_keys/{PUBLIC_KEY_ID}.xml
<?xml version="1.0" encoding="UTF-8"?>
<public_key>
  <name>New Name</name>
</public_key>

Click to expand…

xml http-response
<?xml version="1.0" encoding="UTF-8"?>
<public-key>
  <id type="integer">7</id>    
  <account-id type="integer">8</account-id>
  <user-id type="integer">5638</user-id>
  <name>New Name</name>
  <content>
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
  </content>
  <created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
  <updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>    
</public-key>

--OR IF INVALID--

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>
    A public key can only be used once in each account.
    Since this key already exists for John Doe,
    please generate a new one.
  </error>
</errors>

Delete Public Key

Admins can delete other users’ keys. Regular users can delete their own keys only.

json http-request
DELETE /api/public_keys/{PUBLIC_KEY_ID}.json

Click to expand…

json http-response
HEAD 200 OK
  
--OR IF INVALID--

{
  "errors": ["Name can't be blank"]
}
xml http-request
DELETE /api/public_keys/{PUBLIC_KEY_ID}.xml

Click to expand…

xml http-response
HEAD 200 OK

--OR IF INVALID--

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>Delete failed. Please try again later.</error>
</errors>