To allow an non-authenticated user to make an API call to attach a file on CSM, how can we set?

maitakiguch
Tera Contributor

I want to create a form for non-authenticated users in CSM and implement a feature to attach files there. Since it is impossible to achieve the file attachment feature for non-authenticated users with only CSM, I am considering a method to call an external API and store the files externally.

When calling an external API, I intend to call the API from the ServiceNow instance in order to restrict the source IP. If the user's file attachment window is implemented with client-side scripting, the source IP when calling the API will not be the instance's IP, so I want to avoid this.

Please tell me how to implement it so that non-authenticated users can select files from the file attachment window and call the API from the ServiceNow instance.

1 ACCEPTED SOLUTION

@maitakiguch 

this link has the solution

Allow Guest users to add attachments on Catalog Items/Record Producers 

Note: It's not recommended to do this as lot of unauthenticated users can add files and flood the Attachment table

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

maitakiguch
Tera Contributor

Implementing the file attachment screen using client-side scripting is not mandatory. As long as you can attach files and call external APIs from the ServiceNow instance, please let me know any method that works.

maitakiguch
Tera Contributor

I am implementing the following code so that an unauthenticated user can attach a file in CSM and call an external API to store the file. However, I am having trouble retrieving the contents of the attached file obtained in the client script on the server script.

Could you provide advice on how to retrieve the contents of the attached file obtained in the client script on the server script?


Client Script

c.uploadAttachments2 = function() {
        document.getElementById('fileToUpload').value = '';
        $scope.files.forEach(function(file) {
            $scope.fd = new FormData();
            $scope.fd.append('files', file);
            var fdEntries = $scope.fd.entries();
            var fdEntry = fdEntries.next();
            var entryVal = fdEntry.value;
            c.server.get({
                action: 'uploadFileServer',
                caData: {
                    fileData: entryVal[1]
                }
            }).then(function(r) {
                
            });
        });
    };

 
Server Script

if (input.action == "uploadFileServer") {
            gs.info('0123===' + input.caData.fileData);
        }
        var request = new sn_ws.RESTMessageV2();
        request.setEndpoint('https://xxxxxx.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=xxxxx&file_name=a.txt');
        request.setHttpMethod('POST');

@maitakiguch 

this link has the solution

Allow Guest users to add attachments on Catalog Items/Record Producers 

Note: It's not recommended to do this as lot of unauthenticated users can add files and flood the Attachment table

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@maitakiguch 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader