Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

How to call Now Assist Skills or AI Agent Studio agents via REST API from server-side script?

FrancescoF82933
Tera Contributor

Hi everyone,

I'm working on integrating either a Now Assist Skill or an AI Agent Studio agent into a server-side script (background script in ServiceNow).

Context:

  • I have a custom Now Assist Skill and/or an AI Agent created in AI Agent Studio
  • I need to call one of them from a server-side script to process conversation data and return a response
  • Both have multiple input parameters that need to be passed

What I've tried:

  • REST API endpoint: POST /api/now/v2/assist/skills/execute with skill_name
  • REST API endpoint: POST /api/now/v2/agents/execute with agent_id
  • Both return 401 Unauthorized even with Basic Auth credentials

Question: What is the correct way to invoke a Now Assist Skill or an AI Agent from a server-side script? Is there a specific API endpoint, authentication method, or ServiceNow class I should use?

Any guidance would be appreciated!

Thanks, Francesco

3 REPLIES 3

Vikram Reddy
Tera Guru

Hi @FrancescoF82933 ,

 

Those two endpoints, /api/now/v2/assist/skills/execute and /api/now/v2/agents/execute, are not real, documented ServiceNow REST resources. There is no such out-of-box public REST API for triggering a Now Assist Skill or an AI Agent Studio agent by name or ID. That mismatch, not your Basic Auth credentials, is why you're seeing 401 on both: the request never resolves to a registered resource, so the inbound REST auth layer rejects it before the platform even has a chance to tell you the path doesn't exist.

The good news is you don't need REST at all for this. Since you're already inside a server-side script, use the internal script APIs directly. They differ depending on whether you built a Skill Kit skill or an AI Agent Studio agent.

 

Calling a custom Now Assist Skill (Skill Kit)

The supported pattern is sn_one_extend.OneExtendUtil.execute(request), passing the skill's Capability ID and Skill Config ID inside an executionRequests array along with your input parameters. Rather than hand-typing those sys_ids, open your skill in Now Assist Skill Kit, go to Skill Settings > Deployment Settings, and add a "UI Action" deployment. ServiceNow auto-generates a working script with the correct capability ID and config ID already wired in, which you can copy straight into your background script, Business Rule, or Script Include. That's the documented approach, see Call a custom skill from a script. It looks roughly like this once populated:

var request = {
  executionRequests: [
    {
      capabilityId: '<capability sys_id from generated UI Action>',
      skillConfigId: '<skill config sys_id from generated UI Action>',
      inputParameters: {
        // your skill's actual input parameter names go here
      }
    }
  ]
};
var response = sn_one_extend.OneExtendUtil.execute(request);
gs.info(JSON.stringify(response));

Calling an AI Agent Studio agent

For an agent built in AI Agent Studio, use the AiAgentRuntimeUtil script API and its startAiAgentConversation() method:

var request = {
  targetRecordId: current.sys_id,      // or the sys_id of the record you're working
  targetTable: 'incident',             // table of the target record
  usecaseId: '<use case sys_id>',
  conversationUser: gs.getUserID(),
  objective: 'Summarize this conversation and return key entities',
  conversationLabel: 'Server-side integration run'
};
var aiAgentRuntimeUtil = new AiAgentRuntimeUtil();
var response = aiAgentRuntimeUtil.startAiAgentConversation(request);
gs.info(JSON.stringify(response));

Important caveat: this call is asynchronous. It kicks off the conversation and hands you back conversation and execution IDs, not the agent's final answer in the same script transaction. To get the actual result you'll need to query the execution tables afterward, sn_aia_execution_plan and sn_aia_execution_task are the ones to check for status and output, or design your integration around polling rather than a synchronous request/response. This exact pattern (and its async limitation) is confirmed in the community thread Trigger AI agents from a script.

 

Check roles before assuming the code is wrong

 

Since role-based access became mandatory in AI Agent Studio, every agent runs either as a "Dynamic user" (inherits the invoking user's roles) or as a dedicated "AI user" with preassigned roles, and Skill Kit requires you to explicitly select the roles allowed to execute a skill at creation time. If the identity your script runs as (or the AI user configured on the agent) doesn't hold those roles, execution will fail or return nothing even though the API call itself is correct. Details on how that changed are in Latest access control security enhancements for AI Agents and Skill Kit.

 

Thank you,
Vikram Karety
Octigo Solutions INC

Earl Duque
Administrator

Hi @FrancescoF82933 , my colleague and I both explored this more in depth. Just wanted to share these blog posts:

 

Calling ServiceNow AI Skills via REST API: A Complete Walkthrough

How to Call a ServiceNow AI Agent Using REST API

rpriyadarshy
Kilo Sage

@FrancescoF82933 

 

(1) You Can trigger / execute an AI Agent using Flow Action- Use an AI Agent.

Call/Embed this in a simple flow

 

rpriyadarshy_0-1784780920142.png

 

ser references:

https://www.servicenow.com/community/developer-forum/how-to-invoke-one-ai-agent-from-another-ai-agen...

https://www.servicenow.com/docs/r/build-workflows/workflow-studio/use-an-ai-agent-action.html

 

 

(2) In Your Server Side Script You Can call/execute this FLow which is made in STEP1

 

sn_fd.FlowAPI.Getrunner.Action().InBackground().Run   Or

sn_fd.FlowAPI.Getrunner.subflow('Test_SF').InForeground().withinputs(INPUTS),Run()

 

Useful references: https://www.servicenow.com/docs/r/api-reference/server-api-reference/ScriptableFlowAPI.html

 

You can control the flow call as per you need.

 

U

 

Regards

RP