Skip to content

Invoke-GitHubAPI

SYNOPSIS

Calls the GitHub API using the provided parameters.

SYNTAX

ApiEndpoint (Default)

Invoke-GitHubAPI -ApiEndpoint <string> [-Method <Object>] [-ApiBaseUri <string>] [-Body <Object>]
 [-Accept <string>] [-HttpVersion <string>] [-UploadFilePath <string>] [-ContentType <string>]
 [-ApiVersion <string>] [-RetryCount <int>] [-RetryInterval <int>] [-PerPage <int>] [-Anonymous]
 [-Context <Object>] [<CommonParameters>]

Uri

Invoke-GitHubAPI -Uri <string> [-Method <Object>] [-Body <Object>] [-Accept <string>]
 [-HttpVersion <string>] [-UploadFilePath <string>] [-ContentType <string>] [-ApiVersion <string>]
 [-RetryCount <int>] [-RetryInterval <int>] [-PerPage <int>] [-Anonymous] [-Context <Object>]
 [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

This function is a wrapper around Invoke-RestMethod tailored for calling GitHub's API. It automatically handles the endpoint URI construction, headers, and token authentication.

EXAMPLES

EXAMPLE 1

Invoke-GitHubAPI -ApiEndpoint '/repos/user/repo/pulls' -Method GET

Gets all open pull requests for the specified repository.

EXAMPLE 2

Invoke-GitHubAPI -ApiEndpoint '/repos/user/repo/pulls' -Method GET -Body @{ state = 'open' }

Gets all open pull requests for the specified repository, filtered by the 'state' parameter.

EXAMPLE 3

Invoke-GitHubAPI -ApiEndpoint '/repos/user/repo/pulls' -Method GET -Body @{ state = 'open' } -Accept 'application/vnd.github.v3+json'

Gets all open pull requests for the specified repository, filtered by the 'state' parameter, and using the specified 'Accept' header.

PARAMETERS

-Accept

The 'Accept' header for the API request. If not provided, the default will be used by GitHub's API.

Type: System.String
DefaultValue: application/vnd.github+json; charset=utf-8
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Anonymous

If specified, makes an anonymous request to the GitHub API without authentication.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ApiBaseUri

The base URI for the GitHub API. This is usually https://api.github.com, but can be adjusted if necessary.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ApiEndpoint
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ApiEndpoint

The specific endpoint for the API call, e.g., '/repos/user/repo/pulls'.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ApiEndpoint
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ApiVersion

The GitHub API version to be used. By default, it pulls from a configuration script variable.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Body

The body of the API request. This can be a hashtable or a string. If a hashtable is provided, it will be converted to JSON.

Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases:
- Query
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ContentType

The 'Content-Type' header for the API request. The default is 'application/vnd.github+json'.

Type: System.String
DefaultValue: application/vnd.github+json; charset=utf-8
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Context

The context to run the command in. Used to get the details for the API call. Can be either a string or a GitHubContext object.

Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-HttpVersion

Specifies the HTTP version used for the request.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Method

The HTTP method to be used for the API request. It can be one of the following: GET, POST, PUT, DELETE, or PATCH.

Type: System.Object
DefaultValue: GET
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-PerPage

The number of results per page for paginated GitHub API responses.

Type: System.Nullable`1[System.Int32]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-RetryCount

Specifies how many times PowerShell retries a connection when a failure code between 400 and 599, inclusive or 304 is received.

Type: System.Nullable`1[System.Int32]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-RetryInterval

Specifies the interval between retries for the connection when a failure code between 400 and 599, inclusive or 304 is received. When the failure code is 429 and the response includes the Retry-After property in its headers, the cmdlet uses that value for the retry interval, even if this parameter is specified.

Type: System.Nullable`1[System.Int32]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-UploadFilePath

The file path to be used for the API request. This is used for uploading files.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Uri

The full URI for the API request. This is used for custom API calls.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Uri
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES