From 9c4b0e23f5e55abf67387e1dd7ed33e3ae347056 Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Thu, 22 Sep 2022 13:24:23 +0530 Subject: [PATCH] add section for creating projects using api Co-authored-by: Steve Guntrip Co-authored-by: Hector Alfaro --- .../using-the-api-to-manage-projects.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/content/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects.md b/content/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects.md index 3e15a0797b..44fc59d190 100644 --- a/content/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects.md +++ b/content/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects.md @@ -715,6 +715,61 @@ gh api graphql -f query=' ``` {% endcli %} +## Managing projects + +### Creating projects + +You can use a mutation to create a new project. For more information, see "[About mutations](/graphql/guides/forming-calls-with-graphql#about-mutations)." + +To create a new project using the API, you'll need to provide a name for the project and the node ID of a {% data variables.product.product_name %} user or organization who will become the project's owner. + +You can find the node ID of a {% data variables.product.product_name %} user or organization if you know the username. Replace GITHUB_OWNER with the {% data variables.product.product_name %} username of the new project owner. + +{% curl %} +```shell +curl --request GET \ + --url https://api.github.com/users/GITHUB_OWNER \ + --header 'Authorization: token TOKEN' \ + --header 'Accept: application/vnd.github+json' +``` +{% endcurl %} + +{% cli %} +```shell +gh api -H "Accept: application/vnd.github+json" /users/GITHUB_OWNER +``` +{% endcli %} + +To create the project, replace `OWNER_ID` with the node ID of the new project owner and replace `PROJECT_NAME` with a name for the project. + +{% curl %} +```shell +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token TOKEN' \ + --data '{"query":"mutation {createProjectV2(input: {ownerId: \"OWNER_ID\" title: \"PROJECT_NAME\"}) {projectV2 {id}}}"}' +``` +{% endcurl %} + +{% cli %} +```shell +gh api graphql -f query=' + mutation{ + createProjectV2( + input: { + ownerId: "OWNER_ID", + title: "PROJECT_NAME" + } + ){ + projectV2 { + id + } + } + }' +``` +{% endcli %} + + ## Using webhooks You can use webhooks to subscribe to events taking place in your project. For example, when an item is edited, {% data variables.product.product_name %} can send a HTTP POST payload to the webhook's configured URL which can trigger automation on your server. For more information about webhooks, see "[About webhooks](/developers/webhooks-and-events/webhooks/about-webhooks)." To learn more about the `projects_v2_item` webhook event, see "[Webhook events and payloads](/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2_item)."