Invoke-APITCGRequest

SYNOPSIS

Makes an API request to the APITCG API

SYNTAX

__AllParameterSets

Invoke-APITCGRequest [[-Method] <string>] [-ResourceURI] <string> [[-UriFilter] <hashtable>]
 [[-MultiValueParameter] <string[]>] [[-Headers] <hashtable>] [[-Data] <Object>] [-AllResults]
 [-CursorPaging] [-Raw] [-WhatIf] [-Confirm]

ALIASES

This cmdlet has the following aliases,

  • None

DESCRIPTION

The Invoke-APITCGRequest cmdlet invokes an API request to the APITCG API

This is an internal function that is used by all public functions

Every request is authenticated with the API key (Add-APITCGAPIKey) which is sent in the x-api-key header. The API key is stored as a SecureString & is only decrypted when the request is sent. The API key is never written to the Invoke_APITCGRequest_Parameters debug variable

APITCG wraps its lists in { success, data, total, fallback }. By default only the data of a response is returned. Use -Raw to return the full response. Responses that are not wrapped, such as the health check & the price history (a plain array), are returned as is

Rate limit headers (RateLimit & RateLimit-Policy) of every response, successful or not, are saved in the $APITCGModuleRateLimit variable (see Get-APITCGRateLimit)

Failed requests are handled as follows: 401 The API key is missing or invalid 404 The resource was not found 400 The message of the API is returned 429 A monthly quota error (Request limit reached for this month) is never retried Any other 429 error waits for the Retry-After header and tries again 502-504 GET requests are retried with an exponential backoff (up to 3 attempts), as are network errors

Requests that are not GET requests are write requests. Write requests are never retried and support -WhatIf

EXAMPLES

EXAMPLE 1

Invoke-APITCGRequest -Method GET -ResourceURI '/api/tcgs' -UriFilter @{ limit = 10 }

Invoke a rest method against the defined resource using the provided query parameters

EXAMPLE 2

Invoke-APITCGRequest -ResourceURI '/api/products' -UriFilter @{ tcg = 'one-piece' } -AllResults -CursorPaging

Returns every One Piece product by requesting every page of the results with a cursor

EXAMPLE 3

Invoke-APITCGRequest -Method POST -ResourceURI '/api/products' -Data @{ name = 'Example' } -WhatIf

Shows the write request without sending it

PARAMETERS

-AllResults

Returns all items from an endpoint by requesting every page of the results

Ignored for write requests

By default the page & limit parameters are used (page mode). The first page is the page of the UriFilter (default 1), the limit is the limit of the UriFilter (default 100) & paging stops when a page is empty, is not full, or when the total number of items was collected

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: ''

-Confirm

Prompts you for confirmation before running the cmdlet.

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

-CursorPaging

Uses cursor paging for -AllResults instead of page numbers

The results are sorted by _id (sortBy=_id & sortOrder=asc), the first request uses the afterId of the UriFilter (default 0) & each next request uses the _id of the last item as afterId. Paging stops when a page is empty or is not full. A different sortBy or sortOrder in the UriFilter is not allowed

Cursor paging is the recommended way to copy a large part of a catalog. It is ignored when the UriFilter has a page parameter

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: ''

-Data

Optional object to send as the JSON request body

A string is sent as is and must already be JSON, any other object is converted to JSON

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

-Headers

Hashtable of additional request headers

The x-api-key header cannot be overwritten

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

-Method

Defines the type of API method to use

Allowed values: ‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, ‘DELETE’

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

-MultiValueParameter

Defines the names of the UriFilter keys that must be sent as repeated key\value pairs instead of a comma separated list

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

-Raw

Returns the full API response (success, data, total, & fallback) instead of only the data

With -AllResults a response is returned with all of the items in the data property & the total number of items

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: ''

-ResourceURI

Defines the resource uri (url) path to use when creating the API call, such as /api/products

The path is appended to the base URI defined by Add-APITCGBaseURI

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

-UriFilter

Hashtable of query string parameters to append to the resource uri

Arrays are sent as comma separated lists, dates are converted to UTC, and booleans are sent as lowercase true\false values

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

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  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

N/A