Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$token = '<API_TOKEN>' # account-level API token
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
# create new project
$body = @{
repositoryProvider="gitHub"
repositoryName="<githib_user_name>/<github_repo_name>"
}
$body = $body | ConvertTo-Json
#use 'https://ci.appveyor.com/api/account/<appveyor_account_name>/projects' endpount is using v2 'all accounts' API token
$newProject = Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body $body -Method POST
# read existing project config
# note: by default <appveyor_account_name> is the same as <githib_user_name> and <appveyor_project_name> is the same as <github_repo_name>
$s = Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects/<appveyor_account_name>/<appveyor_project_name>/settings' -Headers $headers -Method Get
# update config with new project data
$s.settings.projectId = $newProject.projectId
$s.settings.slug = ($s.settings.slug + "-new")
# optionally update project name
$s.settings.name = ($newProject.name + "-new")
#update new project
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.