Created attachment is not getting saved to sys_attachement table .(Issue with create & Retrive attachment)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 01:36 AM
HI ,
I have created a attachment & tried to retrieve it by passing id it returns 404 .Adding details below
CASE I
Create Attachment
POST : https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true
Request Body : { source: 'alm_asset:1cab288d3790200044e0bfc8bcbe5d43',
name: 'dev87746.txt',
agent: 'AttachmentCreator',
topic: 'AttachmentCreator',
payload: 'dev87746 service instnace in use' }
Response : Received response 401 from POST call to https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true
It says 401 & still returns response : {"file_name":"dev87746.txt","sys_id":"74c34891db51101065a42946489619a8","FileContent":"dev87746 service instnace in use","AttachmentOwnerType":"alm_asset","AttachmentOwnerId":"00aa7c9edb401010aad88809489619aa"}
Retrive :
Now when i tried to get the attachement by :https://dev87746.service-now.com/api/now/table/sys_attachment/74c34891db51101065a42946489619a8?sysparm_exclude_reference_link=true
it returns 404 .
Retrive Response : {
"error": {
"detail": "Record doesn't exist or ACL restricts the record retrieval",
"message": "No Record found"
},
"status": "failure"
}
CASE II
POST : https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true
This Api returns 201 me sometimes .
RequestBody : { source: 'alm_asset:1cab288d3790200044e0bfc8bcbe5d43',
name: 'dev87746.txt',
agent: 'AttachmentCreator',
topic: 'AttachmentCreator',
payload: 'dev87746 service instnace in use' }
Response: Successful response 201 from POST call to https://dev87746.service-now.com/api/now/table/ecc_queue?&sysparm_exclude_reference_link=true
Response received: {"file_name":"dev87746.txt","sys_id":"6a0a88d9db51101065a42946489619fc","FileContent":"dev87746 service instnace in use","AttachmentOwnerType":"alm_asset","AttachmentOwnerId":"00aa7c9edb401010aad88809489619aa"}
Retrive : https://dev87746.service-now.com/api/now/table/sys_attachment/6a0a88d9db51101065a42946489619fc?sysparm_exclude_reference_link=true
Retrive response : 404
{
"error": {
"detail": "Record doesn't exist or ACL restricts the record retrieval",
"message": "No Record found"
},
"status": "failure"
}
Note : The user role is set to Admin .
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:08 AM
Hi,
Can you try POST URL as:
https://[YOURINSTANCE].service-now.com/ecc_queue.do?JSON&sysparm_action=insert
Refer below link for more details:
http://www.john-james-andersen.com/blog/service-now/generate-attachments-in-servicenow-via-rest.html
Mark ✅ Correct if this solves your issue.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:51 AM
Hi Asha ,
https://[YOURINSTANCE].service-now.com/ecc_queue.do?JSON&sysparm_action=insert
it returns {
"error": {
"detail": null,
"message": "Invalid table ecc_queue.do"
},
"status": "failure"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:31 AM
Hi,
Few things you need to check/confirm
1) the payload accepts base64encoded string and not plain string text
2) Also you need to give the content-type for the file
3) Did you verify on the target record the attachment is formed correctly?
use this website to convert plain text to base64 encoded string
4) Also in the API response I don't think it returns the sys_id of the sys_attachment table
Probably that error says no record found when you are using GET method on sys_attachment
5) Attachment data is stored as meta data in table (sys_attachment_doc)
Try this; I have updated the file type and given the base64encoded string there
{ source: 'alm_asset:1cab288d3790200044e0bfc8bcbe5d43',
name: 'dev87746.txt:text/plain',
agent: 'AttachmentCreator',
topic: 'AttachmentCreator',
payload: 'ZGV2ODc3NDYgc2VydmljZSBpbnN0bmFjZSBpbiB1c2U' }
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:57 AM
Hi Ankur ,
Below is the response after creating attachment , Did you mean the higlighted sys_id won't return the attachment ? . Also i am wondering why the create attachment returns 401 sometimes when the payload is same ?
{
"result": {
"agent": "AttachmentCreator",
"response_to": "",
"sys_mod_count": "0",
"from_sys_id": "",
"source": "incident:eadd8830db41101065a429464896192a",
"sys_updated_on": "2020-06-08 12:53:32",
"agent_correlator": "",
"priority": "2",
"sys_domain_path": "/",
"error_string": "",
"processed": "",
"sequence": "17293fe3d4e0000001",
"sys_id": "d5a7419ddbd1101065a4294648961925",
"sys_updated_by": "admin",
"from_host": "",
"payload": "Attachment created and attached to 'incident' record with sys_id: 'eadd8830db41101065a429464896192a'",
"sys_created_on": "2020-06-08 12:53:32",
"sys_domain": "global",
"name": "dev87746.txt",
"topic": "AttachmentCreator",
"state": "processed",
"queue": "input",
"sys_created_by": "admin"
}
}