< Back

Invoke-JiraMethod

Thu Jan 16, 2020 8:05 am

NAME Invoke-JiraMethod



SYNOPSIS

Invoke a specific call to a Jira REST Api endpoint





SYNTAX

Invoke-JiraMethod [-URI] <Uri> [[-Method] {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge |

Patch}] [[-Cmdlet] <PSCmdlet>] [[-Body] <String>] [[-Headers] <Hashtable>] [[-GetParameter] <Hashtable>]

[[-Paging]] [[-InFile] <String>] [[-OutFile] <String>] [[-StoreSession]] [[-OutputType] <String>] [[-Credential]

<PSCredential>] [-RawBody] [-IncludeTotalCount] [-Skip <UInt64>] [-First <UInt64>] [<CommonParameters>]





DESCRIPTION

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.





PARAMETERS

-URI <Uri>

URI address of the REST API endpoint.



Required? true

Position? 0

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Method <WebRequestMethod>

Method of the HTTP request.



Required? false

Position? 1

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Body <String>

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/152 ... rs-in-json



This behavior can be changed with -RawBody.



Required? false

Position? 2

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-RawBody [<SwitchParameter>]

Keep the Body from being encoded.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Headers <Hashtable>

Define a key-value set of HTTP headers that should be used in the call.



Required? false

Position? 3

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-GetParameter <Hashtable>

Key-Value pair of the Headers to be used.



Required? false

Position? 4

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Paging [<SwitchParameter>]

Use paging on the results.



More about paging: <https://docs.atlassian.com/software/jir ... pagination>



Required? false

Position? 4

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-InFile <String>

Path to a file that will be uploaded with a multipart/form-data request.



This parameter does not validate the input in any way.



Required? false

Position? 5

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-OutFile <String>

Path to the file where the response should be stored to.



This parameter does not validate the input in any way



Required? false

Position? 6

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-StoreSession [<SwitchParameter>]

Instead of returning the response, it returns a `[JiraPS.Session]` which contains the `[WebRequestSession]`.



Required? false

Position? 7

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-OutputType <String>

Name of the data type that is expected to be returned.



Currently only used in combination with `-Paging`



Required? false

Position? 8

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Credential <PSCredential>

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.



Required? false

Position? 9

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Cmdlet <PSCmdlet>

Context which will be used for throwing errors.



Required? false

Position? 10

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-IncludeTotalCount [<SwitchParameter>]

Causes an extra output of the total count at the beginning.



Note this is actually a uInt64, but with a custom string representation.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Skip <UInt64>

Controls how many things will be skipped before starting output.



Defaults to 0.



Required? false

Position? named

Default value 0

Accept pipeline input? False

Accept wildcard characters? false



-First <UInt64>

Indicates how many items to return.



Required? false

Position? named

Default value 18446744073709551615

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

[System.Management.Automation.PSCustomObject]

This command is designed to handle JSON responses only. The response is convert to PSCustomObject with

`ConvertFrom-Json`





NOTES









-------------------------- Example 1 --------------------------



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.

-------------------------- Example 2 --------------------------



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.

-------------------------- Example 3 --------------------------



$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

-------------------------- Example 4 --------------------------



$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"

-------------------------- Example 5 --------------------------



$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]`.

-------------------------- Example 6 --------------------------



$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.

-------------------------- Example 7 --------------------------



$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.

-------------------------- Example 8 --------------------------



$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.



RELATED LINKS

Online Version: https://atlassianps.org/docs/JiraPS/com ... iraMethod/

Jira Cloud API https://developer.atlassian.com/cloud/j ... form/rest/

Jira Server API https://docs.atlassian.com/software/jir ... EST/7.6.1/