How to create Api with oauth so any other third party tool can consume

Debasis Pati
Kilo Sage

Hello All,
I want to expose one api with one thirdpart tool but it should also have ouath as authenticaion method.

How i should create this?

Any idea @Ankur Bawiskar ?

1 ACCEPTED SOLUTION

@Debasis Pati 

you are using GlideRecordSecure so it will evaluate ACL and ACL must be blocking the READ Access

Please use GlideRecord and it will work fine with Postman

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

12 REPLIES 12

@Debasis Pati 

if it works from API explorer because you are admin

Remember OOTB there is query BR on incident table which restricts access

Share your complete scripted REST API script and how are you testing from API explorer and from postman

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hello @Ankur Bawiskar ,

DebasisPati_0-1770879601130.png
Scripted rest api resource-

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    // implement resource here
    var incidentNumber = request.pathParams.incident_number; // Access the path parameter
    var incidentDetails = {};

    var gr = new GlideRecordSecure('incident'); // Use GlideRecordSecure for ACL enforcement
    if (gr.get('number', incidentNumber)) { // Query by incident number
        incidentDetails.number = gr.getValue('number');
        incidentDetails.sys_id = gr.getValue('sys_id');
        incidentDetails.short_description = gr.getValue('short_description');
        incidentDetails.state = gr.getDisplayValue('state'); // Get display value for choice fields
        incidentDetails.priority = gr.getDisplayValue('priority');
        // Add more fields as needed

        response.setStatus(200); // OK
        response.setBody(incidentDetails);
    } else {
        response.setStatus(404); // Not Found
        response.setBody({
            error: "Incident not found with number: " + incidentNumber
        });
    }

})(request, response);

DebasisPati_1-1770879707170.png

 

 

@Debasis Pati 

you are using GlideRecordSecure so it will evaluate ACL and ACL must be blocking the READ Access

Please use GlideRecord and it will work fine with Postman

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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