Search code examples
apigithubgithub-apigithub-pagescircleci

Does the CircleCI API command "New Checkout Key" work for type "github-user-key"?


I am trying to use CircleCI's REST API to create a "New Checkout Key" of type "github-user-key".

If I run :

curl -X POST \ 
--header "Content-Type: application/json" \ 
-d '{"type":"deploy-key"}' \ 
https://circleci.com/api/v1/project/myOrg/myPrj/checkout-key?circle-token=8e9c47...etc

I get :

{ 
"public_key" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA . . . pRYe+9SHcZFs4n \n", 
"type" : "deploy-key", 
"fingerprint" : "b0:cd:e8:77:ef:00:d5:da:62:b7:fc:d9:9e:84:f7:f1", 
"login" : null, 
"preferred" : true, 
"time" : "2015-11-20T14:57:43.379Z" 
}

If I run :

curl -X POST \ 
--header "Content-Type: application/json" \ 
-d '{"type":"user-key"}' \ 
https://circleci.com/api/v1/project/myOrg/myPrj/checkout-key?circle-token=8e9c47...etc

I get :

{ 
"message" : "Invalid checkout key type (valid types are deploy-key and github-user-key)" 
}

If I run :

curl -X POST \ 
--header "Content-Type: application/json" \ 
-d '{"type":"github-user-key"}' \ 
https://circleci.com/api/v1/project/myOrg/myPrj/checkout-key?circle-token=8e9c47...etc

I get :

{ 
"message" : "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3\"}" 
}

I suspect the documentation for the command is incomplete.

Does anyone know how to do this?


Solution

  • In order to be able to add a user key to your project, CircleCI needs permissions from GitHub to add SSH keys to your account. You can grant it permission by visiting Project Settings > Permissions > Checkout SSH keys for any of your projects and clicking on Authorize w/ GitHub. After doing this, you should be able to generate a checkout key of type github-user-key for any of your other projects using the curl command you demonstrated.