Search notes:

github Web API: v4 / GraphQL

create repository

The following PowerShell function tries to demonstrate how a repository can be created on GitHub with github's GraphQL interface.
function create-repository($name, $visibility, $token) {
 #
 # Prepare query string with new lines:
 #
   $query_nl = '
      mutation {{
         createRepository (
            input: {{
               name      : \"{0}\",
               visibility:   {1}
            }}
         )
         {{
             clientMutationId
         }}
    }}' -f $name, $visibility

    write-verbose "query with newlines:`n$($query_nl)"

 #
 # Apparently, graphql and/or github does not allow new lines in the query string.
 # So, replace them
 #
   $query = $query_nl.replace("`n", '').replace("`r", '')

   $body = '{{ "query": "{0}" }}' -f $query

   $response = invoke-webrequest `
       https://api.github.com/graphql                          `
      -method         POST                                     `
      -contentType    application/json                         `
      -headers @{Authorization = "Bearer $token"}              `
      -body           $body

 #
 # Note: response might be '200 OK' even if repository was not created.
 #
   write-host "$($response.StatusCode) $($response.StatusDescription)"
}
Github repository github-web-API, path: /v4-GraphQL/create-repository.ps1
After installing the function, it can be executed like so:
$token = '…'
PS:\> create-repository github-web-API PUBLIC $token

See also

Web APIs

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206304, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/version-control-systems/git/github/web-API/v4-GraphQL/index(87): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78