Servicenow

De Banane Atomic
Aller à la navigationAller à la recherche

Liens

REST API

Bash.svg
curl --header "Accept: application/json" \
--user "john.doe:password" --cookie cookies.txt --cookie-jar cookies.txt \
"https://myinstance.service-now.com/api/now/v2/table/sys_user?user_name=john.doe&sysparm_fields=user_name,first_name,last_name,sys_id"
Json.svg
{
  "result": [
    {
      "first_name": "John",
      "last_name": "Doe",
      "sys_id": "ea2bc1b14f4212008a5ab895f110c7d1",
      "user_name": "john.doe"
    }
  ]
}
Bash.svg
curl --verbose --request POST \
--header "Accept: application/json" --header "Content-Type: application/json" \
--cookie cookies.txt --cookie-jar cookies.txt \
--data '{"comment":"Hello, world!"}' \
"https://myinstance.service-now.com/api/x_snc_my_work/v1/tracker/task/d7296d02c0a801670085e737da016e70/comment"

ServiceNowRESTClient in C#

Users

Cs.svg
var usersTable = new TableAPIClient<sys_user>("sys_user", instance, userName, password);

// get user
var response = usersTable.GetByQuery($"first_name={firstname}^last_name={lastname}");
if (response.IsError)
{
    throw new Exception(response.ErrorMsg);
}
else
{
    var user = response.Result.SingleOrDefault();
}

// create user
var user = new sys_user()
{
    first_name = firstname,
    last_name = lastname,
    location = new ResourceLink() { value = "" }
};
var response = _usersTable.Post(user);
if (response.IsError)
{
    throw new Exception(response.ErrorMsg);
}
else
{
    var newlyCreatedUser = response.Result;
}

Incidents

Cs.svg
var incidentsTable = new TableAPIClient<incident>("incident", instance, userName, password);

// get incident
var response = _incidentsTable.GetByQuery($"caller_id={userId}^state=1");
if (response.IsError)
{
    throw new Exception(response.ErrorMsg);
}
else
{
    ICollection<incident> incidents = response.Result;
}

// create incident
var incident = new incident()
{
    active = true,
    description = description,
    short_description = shortDescription,
    caller_id = new ResourceLink() { value = user.sys_id },
    // leave it like it, admin user will be used
    opened_by = new ResourceLink() { value = "" }
};
var response = _incidentsTable.Post(incident);
if (response.IsError)
{
    throw new Exception(response.ErrorMsg);
}
else
{
    var newlyCreatedIncident = response.Result;
}

REST API Client .NET

Pas de Post

Package Nuget: ServiceNow.Api

Cs.svg
var serviceNow = new ServiceNowClient("dev00000", "admin", "password");

List<JObject> result = serviceNow.GetAllByQuery("sys_user", "user_name=admin").GetAwaiter().GetResult();

Erreurs

Data Policy Exception: Close notes is mandatory

Incidents → Incident → Additional Actions (3 bars en haut à gauche) → Configure → Form Layout → Resolution notes

Web Site

Notifications System Notification → Email → Notifications
REST API Explorer System Web Services → REST API Explorer doc

Knowledge Base

Scripted search sources

Service Portal → Portals → My Portal → Search Sources → New