Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Created November 15, 2016 09:18
Show Gist options
  • Save IlyaFinkelshteyn/a50029e48eccab12d0e16afe236d9274 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/a50029e48eccab12d0e16afe236d9274 to your computer and use it in GitHub Desktop.
$token = '<API_Token>'
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
$body = @{
accountName="<Your_account>"
projectSlug="<Your_project_slug>"
branch="<Your_branch>"
commitId="<Your_commit_id>"
}
$body = $body | ConvertTo-Json
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/builds' -Headers $headers -Body $body -Method POST
@canton7
Copy link

canton7 commented Oct 22, 2018

Note: You need to use the URL https://ci.appveyor.com/api/account/<account>/builds.

The AppVeyor docs seem to be out of date (I get "Project not found or access denied" with the code above), but this is what the website does.

@IlyaFinkelshteyn
Copy link
Author

@canton7 this works as well, but you need to use API token for specific account, not the one which is for all accounts.

@webmaster128
Copy link

curl equivalent:

curl -X POST -H "Content-type: application/json" -H "Authorization: Bearer <API_Token>" -d '{"accountName": "<Your_account>", "projectSlug": "<Your_project_slug>", "branch": "<Your_branch>", "commitId": "<Your_commit_id>"}' https://ci.appveyor.com/api/builds

ps.: I leave out commitId in order to build the latest commit of the branch

@MingweiSamuel
Copy link

MingweiSamuel commented Oct 15, 2019

Here is a script your can run in your browser's javascript terminal, so you don't need to bother with auth (run on project's page)

var [, , accountName, projectSlug] = document.location.pathname.split('/');
fetch(`https://ci.appveyor.com/api/account/${accountName}/builds`,
{
	method: "POST",
	headers: {
		'Content-Type': 'application/json',
	},
	body: JSON.stringify({
		accountName,
		projectSlug,
		// from commit
		commitId: 'aa03f23db584039251006b9df9646a19c907bff8', // CHANGE ME
		branch: 'master', // CHANGE ME
		// // or from PR
		// pullRequestId: 3,
		// // env vars
		// "environmentVariables": {
		//	"my_var": "value",
		//	"another_var": "another value"
		// }
	}),
});

@andymac4182
Copy link

Wow. I really hope they could even add this script as a button on the page... Seems fairly simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment