Post an image(base64 encoded string) directly to image type field on form using REST API
we are about to post base64 Encoded string to image type field
step-1 : lets create a image type field on incident form with the following configurations
step-2 : Select any image that you want to post to the above field, and navigate HERE to convert image to base64 encoded string. keep the browser tab open we will need the above base64 encoded string later on.
step-3 : here is the endpoint which we will use to post base64 encoded string directly to the image type field, https://yourInstanceName.service-now.com/api/now/table/ecc\_queue
we will use post man for chrome to post base64 encoded string
endpoint details
METHOD : POST
BODY : application/json
BODYTemplate :
{
"agent":"AttachmentCreator",
"topic":"AttachmentCreator",
"name":"u_profile_photo:image/jpg",
"source":"incident:7b3e4a7cf0212300964feeefe80ff04b",
"payload":"/9j/4AAQSkZJRgABAQEBLAEsAA"
}
keep the agent and topic as AttachmentCreator
name: you should provide field name here to which you want to post an image. here our field name is u_profile_photo and after colon provide image type.
source: source will contain a colon separated table name and sys_id of a record to which you want to post an image.
payload: this is our base64 encoded string that we need to pass here.
step-4: lets start building the above request using post man.
keep the Authentication as Basic Auth and provide admin username and password,
now hit the send button and you will get the response something like this
Here is the end result of how will image look like on the form.
mark this as helpful if this helped, if you have any queries please do post.
thanks & Regards
Hammad Ul Aziz (Sr. Developer)
https://www.servicenow.com/community/developer-articles/post-an-image-base64-encoded-string-directly-to-image-type-field/ta-p/2307331