New-ITGlueAttachment
SYNOPSIS
Create an attachment for a specific object ID
SYNTAX
__AllParameterSets
New-ITGlueAttachment [-ResourceType] <string> [-ResourceId] <long> -Data <Object> [-Raw] [-WhatIf]
[-Confirm]
ALIASES
This cmdlet has the following aliases,
- None
DESCRIPTION
The New-ITGlueAttachment cmdlet invokes the POST method of the /{resource_type}/{resource_id}/relationships/attachments endpoint (Create an attachment for a specific object ID)
Attaches a file to the asset specified in the ID parameter. Returns the created object if successful. Can also be used to add multiple attachments to an asset in bulk.
Attachments are uploaded by including media data on the asset the attachment is associated with. Attachments can be encoded and passed in JSON format for direct upload, in which case the file has to be strict encoded. You need to convert it using something like www.freeformatter.com/base64-encoder.html. This produces a string of text that goes into the ‘content’ field. Note that the name of the attachment displayed on the asset view screen will be taken from the ‘file_name’ attribute.
The request body must contain a JSON object, for example:
{ “data”: { “type”: “attachments”, “attributes”: { “attachment”: { “content”: “R0lGODlhABAQAIAAAAAAAP///yH7BAEAAAAALAAAAAAEAABAAAIBRAA5”, “file_name”: “test.png” } } } }
To create multiple attachments, the JSON object will look something like:
{ “data”: [ { “type”: “attachments”, “attributes”: { “attachment”: { “content”: “R0lGODlhABAQAIAAAAAAAP///yH7BAEAAAAALAAAAAAEAABAAAIBRAA5”, “file_name”: “test.png” } } }, { “type”: “attachments”, “attributes”: {…} } ] }
Multipart requests can also be used to create attachment with uploaded file. Here is a sample curl request:
curl -v
-H “Content-Type: multipart/form-data”
-H “x-api-key: ITG.**********”
-X POST
-F “data[type]=attachments”
-F “data[attributes][attachment]=@test.png”
http://api.itglue.com/api/configurations/1/relationships/attachments’
This is a write function. It changes data in ITGlue. Use -WhatIf to see the request without sending it
EXAMPLES
EXAMPLE 1
New-ITGlueAttachment -ResourceType 'checklists' -ResourceId 12345 -Data @{} -WhatIf
Shows the POST request to the /{resource_type}/{resource_id}/relationships/attachments endpoint without sending it
PARAMETERS
-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: ''
-Data
Defines the data of the JSON:API request body. Accepts a hashtable, an object, or a JSON string
The value is sent as the data property of the request body, such as @{ type = ‘organizations’; attributes = @{ name = ‘Example’ } }. An object with a single data property & a JSON string are sent as is
Body properties:
- type (string) - attachments
- attributes (object):
- attachment (string) - Can be an uploaded file if multipart is used, or a JSON with Base64 encoded content as following:
Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Raw
Returns the full API response (data, meta, links, & included) instead of only the data
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: ''
-ResourceId
The resource id of the parent resource.
Type: System.Int64
DefaultValue: 0
SupportsWildcards: false
Aliases:
- resource_id
ParameterSets:
- Name: (All)
Position: 1
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-ResourceType
The resource type of the parent resource
Allowed values: ‘checklists’, ‘checklist_templates’, ‘configurations’, ‘contacts’, ‘documents’, ‘domains’, ‘locations’, ‘passwords’, ‘ssl_certificates’, ‘flexible_assets’, ‘tickets’
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases:
- resource_type
ParameterSets:
- Name: (All)
Position: 0
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
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
System.String
System.Int64
OUTPUTS
NOTES
Endpoint : POST /{resource_type}/{resource_id}/relationships/attachments