Invoke-GitHubAPI¶
SYNOPSIS¶
Calls the GitHub API using the provided parameters.
SYNTAX¶
ApiEndpoint (Default)¶
Invoke-GitHubAPI [-Method <WebRequestMethod>] [-ApiBaseUri <String>] -ApiEndpoint <String> [-Body <Object>]
[-Accept <String>] [-HttpVersion <String>] [-UploadFilePath <String>] [-DownloadFilePath <String>]
[-ContentType <String>] [-ApiVersion <String>] [-Context <Object>] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
Uri¶
Invoke-GitHubAPI [-Method <WebRequestMethod>] [-Body <Object>] [-Accept <String>] [-HttpVersion <String>]
[-UploadFilePath <String>] [-DownloadFilePath <String>] -URI <String> [-ContentType <String>]
[-ApiVersion <String>] [-Context <Object>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
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¶
-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: WebRequestMethod
Parameter Sets: (All)
Aliases:
Accepted values: Default, Get, Head, Post, Put, Delete, Trace, Options, Merge, Patch
Required: False
Position: Named
Default value: GET
Accept pipeline input: False
Accept wildcard characters: False
-ApiBaseUri¶
The base URI for the GitHub API.
This is usually https://api.github.com
, but can be adjusted if necessary.
Type: String
Parameter Sets: ApiEndpoint
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ApiEndpoint¶
The specific endpoint for the API call, e.g., '/repos/user/repo/pulls'.
Type: String
Parameter Sets: ApiEndpoint
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-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: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Accept¶
The 'Accept' header for the API request. If not provided, the default will be used by GitHub's API.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Application/vnd.github+json; charset=utf-8
Accept pipeline input: False
Accept wildcard characters: False
-HttpVersion¶
Specifies the HTTP version used for the request.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-UploadFilePath¶
The file path to be used for the API request. This is used for uploading files.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DownloadFilePath¶
The file path to be used for the API response. This is used for downloading files.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-URI¶
The full URI for the API request. This is used for custom API calls.
Type: String
Parameter Sets: Uri
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ContentType¶
The 'Content-Type' header for the API request. The default is 'application/vnd.github+json'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Application/vnd.github+json; charset=utf-8
Accept pipeline input: False
Accept wildcard characters: False
-ApiVersion¶
The GitHub API version to be used. By default, it pulls from a configuration script variable.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-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: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-GitHubContext)
Accept pipeline input: False
Accept wildcard characters: False
-ProgressAction¶
{{ Fill ProgressAction Description }}
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters¶
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.