Invoke a specific call to a Jira REST Api endpoint
Invoke-JiraMethod [-URI] <Uri> [[-Method] <WebRequestMethod>] [[-Body] <String>] [-RawBody]
[[-Headers] <Hashtable>] [[-GetParameter] <Hashtable>] [[-Paging] <Switch>] [[-InFile] <String>]
[[-OutFile] <String>] [-StoreSession] [[-OutputType] <String>] [[-Credential] <PSCredential>]
[[-Cmdlet] <System.Management.Automation.PSCmdlet>] [<CommonParameters>]
Make a call to a REST Api endpoint with all the benefits of JiraPS.
This cmdlet is what the other cmdlets call under the hood. It handles the authentication, parses the response, handles exceptions from Jira, returns specific objects and handles the differences between versions of Powershell and Operating Systems.
JiraPS does not support any third-party plugins on Jira. This cmdlet can be used to interact with REST Api enpoints which are not already coverted in JiraPS. It allows for anyone to use the same technics as JiraPS uses internally for creating their own functions or modules. When used by a module, the Manifest (.psd1) can define the dependency to JiraPS with the ‘RequiredModules’ property. This will import the module if not already loaded or even download it from the PSGallery.
Invoke-JiraMethod -URI "$(Get-JiraConfigServer)/rest/api/latest/project"
Sends a GET request which will return all the projects on the Jira server. This call would either be executed anonymously or require a session to be available.
Invoke-JiraMethod -URI "$(Get-JiraConfigServer)/rest/api/latest/project" -Credential (Get-Credential)
Prompts the user for his Jira credentials and send a GET request, which will return all the projects on the Jira server.
$parameter = @{
URI = "$(Get-JiraConfigServer)/rest/api/latest/project"
Method = "POST"
Credential = $cred
}
Invoke-JiraMethod @parameter
Sends a POST request to the server.
This will example doesn’t really do anything on the server, as the content API needs requires a value for the BODY.
See next example
$body = '{"name": "NewGroup"}'
$params = @{
Uri = "$(Get-JiraConfigServer)/rest/api/latest/group"
Method = "POST"
Body = $body
Credential = $cred
}
Invoke-JiraMethod @params
Creates a new group named “NewGroup”
$params = @{
Uri = "$(Get-JiraConfigServer)/rest/api/latest/mypermissions"
Method = "GET"
Body = $body
StoreSession = $true
Credential = $cred
}
Invoke-JiraMethod @params
Executes the GET request but instead of returning the response,
it returns a [JiraPS.Session]
which contains the [WebRequestSession]
.
$params = @{
Uri = "$(Get-JiraConfigServer)/rest/api/latest/issue/10000"
Method = "POST"
InFile = "c:\temp\20001231_Connection.log"
Credential = $cred
}
Invoke-JiraMethod @params
Executes a POST request on the defined URI and uploads the InFile with a multipart/form-data request.
$parameter = @{
URI = "$(Get-JiraConfigServer)/rest/api/latest/project"
Method = "GET"
OutFile = "c:\temp\jira_projects.json"
Credential = $cred
}
Invoke-JiraMethod @parameter
Executes a GET request on all available projects and stores the response json in the defined file.
$parameter = @{
URI = "$(Get-JiraConfigServer)/rest/api/latest/project"
Method = "GET"
Headers = @{"Accept" = "text/plain"}
OutFile = "c:\temp\jira_projects.json"
Credential = $cred
}
Invoke-JiraMethod @parameter
Executes a GET request on the defined URI and stores the output on the File System. It also uses the Headers to define what mimeTypes are expected in the response.
URI address of the REST API endpoint.
Type: Uri
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Method of the HTTP request.
Type: WebRequestMethod
Parameter Sets: (All)
Aliases:
Accepted values: Default, Get, Head, Post, Put, Delete, Trace, Options, Merge, Patch
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Body of the HTTP request.
By default each character of the Body is encoded to a sequence of bytes. This enables the support of UTF8 characters. And was first reported here: https://stackoverflow.com/questions/15290185/invoke-webrequest-issue-with-special-characters-in-json
This behavior can be changed with -RawBody.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Keep the Body from being encoded.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Define a key-value set of HTTP headers that should be used in the call.
Type: Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Key-Value pair of the Headers to be used.
Type: Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Use paging on the results.
More about paging: https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#pagination
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Path to a file that will be uploaded with a multipart/form-data request.
This parameter does not validate the input in any way.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Path to the file where the response should be stored to.
This parameter does not validate the input in any way
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Instead of returning the response, it returns a [JiraPS.Session]
which contains the [WebRequestSession]
.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Name of the data type that is expected to be returned.
Currently only used in combination with -Paging
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 8
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Credentials to use for the authentication with the REST Api.
If none are provided, Get-JiraSession
will be used for authentication.
If no sessions is available, the request will be executed anonymously.
Type: PSCredential
Parameter Sets: (All)
Aliases:
Required: False
Position: 9
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Context which will be used for throwing errors.
Type: PSCmdlet
Parameter Sets: (All)
Aliases:
Required: False
Position: 10
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Causes an extra output of the total count at the beginning.
Note this is actually a uInt64, but with a custom string representation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Controls how many things will be skipped before starting output.
Defaults to 0.
Type: UInt64
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
Indicates how many items to return.
Type: UInt64
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 18446744073709551615
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
This command is designed to handle JSON responses only.
The response is convert to PSCustomObject with ConvertFrom-Json