API & Macros - Can't add attachments
In summary I'm trying to build a Powershell script that is going to allow a couple of my users update the attachment to an existing macro without giving them admin access.
As far as I can tell there's no way to remove an existing attachment and insert a new attachment to a macro, so I'm building the script to delete the existing macro and create a new one with the updated attachment.
I have uploaded a file (in this case, a JPEG as a test) using the API via Postman which was a success. I am now trying to create a macro and attach the image, but I keep getting a 400 Bad Request.
Uri I am using is https://nutripath.zendesk.com/api/v2/macros.json
Here is the body of the request:
{
"macro":{
"title": "BF_Test_3",
"actions": [{"field": "status", "value": "open"}],
"active": "true",
"attachments": [
16919163324185
]
}
}
The attachment exists because if I GET https://nutripath.zendesk.com/api/v2/attachments/16919163324185.json I get the below response.
{
"attachment": {
"url": "https://redacted.zendesk.com/api/v2/attachments/16919163324185.json",
"id": 16919163324185,
"file_name": "20230203121449.jpg",
"content_url": "https://redacted.zendesk.com/attachments/token/redacted/?name=20230203121449.jpg",
"mapped_content_url": "https://redacted.zendesk.com/attachments/token/redacted/?name=20230203121449.jpg",
"content_type": "image/jpeg",
"size": 3322588,
"width": null,
"height": null,
"inline": false,
"deleted": false,
"malware_access_override": false,
"malware_scan_result": "malware_not_found",
"thumbnails": []
}
}
Am I missing something obvious here?
-
Hi Nutripath IT Team,
Are you creating macro attachments specifically? This must be done with our Create Macro Attachment endpoint rather than our Uploads endpoint for ticket attachments.
-
Thanks Chris, I can see where I went wrong there. I am now trying to upload and attach a file to a macro as per the 'Create Macro Attachment' section in the API doc, but this is failing - both in Postmane and via Powershell.
In Postman I've got the 'attachment' field working fine, but still getting a 400 bad request for the file name field:
In my Powershell script I am still trying to work out how to write the invoke-webrequest command, but seeing this (code below):
$newFN = "C:\Users\BrettF\Desktop\20230203121449.jpg"$Fields = @{'attachment' = $newFN; 'filename' = '20230203121449.jpg'}
Invoke-WebRequest -Uri 'https://nutripath.zendesk.com/api/v2/macros/redacted/attachments.json' -Headers @{'Authorization' = 'Basic [redacted]'} -Method 'POST' -ContentType 'multipart/form-data' -Body $Fields -
No problem. I did some testing and I can replicate this in cases where the macro does not add a comment. Since the attachment would be used in the comment added by the macro, a comment must be present in the macro actions to add the attachment. Does the error still persist when adding an attachment to a macro that adds a comment?
Por favor, entrar para comentar.
3 Comentários