ServiceNow.Api
1.3.26
dotnet add package ServiceNow.Api --version 1.3.26
NuGet\Install-Package ServiceNow.Api -Version 1.3.26
<PackageReference Include="ServiceNow.Api" Version="1.3.26" />
<PackageVersion Include="ServiceNow.Api" Version="1.3.26" />
<PackageReference Include="ServiceNow.Api" />
paket add ServiceNow.Api --version 1.3.26
#r "nuget: ServiceNow.Api, 1.3.26"
#:package ServiceNow.Api@1.3.26
#addin nuget:?package=ServiceNow.Api&version=1.3.26
#tool nuget:?package=ServiceNow.Api&version=1.3.26
ServiceNow.Api
Usage
To create a simple command line app that uses the ServiceNow REST API:
- Create a .NET Core 10.0 Console project in Visual Studio
- Ensure that you have specified <LangVersion>latest</LangVersion> in the csproj file, e.g.:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AnalysisMode>Recommended</AnalysisMode>
<AnalysisLevel>latest-recommended</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ServiceNow.Api" Version="1.2.*" />
</ItemGroup>
</Project>
- Edit Program.cs to be similar to the following:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace ServiceNow.Api.Example;
public static class Program
{
public async static Task Main(string[] args)
{
var account = args[0];
var username = args[1];
var password = args[2];
Console.WriteLine("Lists Windows Servers");
using var serviceNowClient = new ServiceNowClient(account, username, password, new Options());
// MANDATORY: The table name can be obtained from this list:
// https://docs.servicenow.com/bundle/london-platform-administration/page/administer/reference-pages/reference/r_TablesAndClasses.html
const string tableName = "cmdb_ci_win_server";
// OPTIONAL: The main sysparm_query goes here. See documentation here:
// https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/reference/r_TableAPI-GET.html
// If you omit this, an unfiltered result will be returned
const string query = "name";
// OPTIONAL: The fields to bring back.
// This should be set to constrain the response to ONLY the fields that you are going to process.
// Doing so will hugely speed up your query.
var fields = new List<string> { "sys_id", "name" };
var jObjectResults = await serviceNowClient.GetAllByQueryAsync(
tableName,
query,
fields
).ConfigureAwait(false);
var modelResults = jObjectResults.ConvertAll(o => o.ToObject<WinServerModel>());
Console.WriteLine("Windows Servers:");
foreach (var modelResult in modelResults)
{
Console.WriteLine($" - {modelResult.Id}: {modelResult.Name}");
}
}
}
[DataContract]
public class WinServerModel
{
[DataMember(Name = "sys_id")]
public string Id { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.26 | 513 | 8/4/2026 |
| 1.3.23 | 153 | 8/4/2026 |
| 1.3.8 | 15,188 | 12/18/2025 |
| 1.3.7 | 14,476 | 7/3/2025 |
| 1.3.1 | 29,620 | 8/13/2024 |
| 1.2.60 | 31,595 | 2/23/2023 |
| 1.2.36 | 23,004 | 5/10/2022 |
| 1.2.34 | 19,160 | 4/9/2021 |
| 1.2.32 | 733 | 3/30/2021 |
| 1.2.28 | 649 | 3/29/2021 |
| 1.2.27 | 2,891 | 12/22/2020 |
| 1.2.20 | 3,736 | 5/21/2020 |
| 1.2.17 | 860 | 5/7/2020 |
| 1.2.9 | 15,159 | 12/11/2019 |
| 1.2.8 | 1,315 | 10/3/2019 |
| 1.2.7 | 821 | 10/3/2019 |
| 1.2.6 | 773 | 10/3/2019 |
| 1.2.5 | 859 | 9/4/2019 |
| 1.2.2 | 1,219 | 8/19/2019 |
| 1.1.21 | 1,121 | 7/19/2019 |
Fixes paging when the ordering field is not a plain UTC string.
Paging read the ordering field with ToString() and appended "Z" to it. With sysparm_display_value=all every field is returned as an object holding a display value and a raw value, so that produced JSON where a timestamp was expected and the query failed outright.
Less visibly, Newtonsoft converts ISO-8601 text to a DateTime while deserialising, shifting it to the host's local timezone, and rendering that back to a string then applied the host's culture. On an en-GB machine running in UTC+7 a value of 2026-01-02T05:00:00+05:00 produced a paging window of 2026-02-01 07:00:00, a month adrift, with no error raised. Being host-dependent, this behaved differently on a build agent than on a developer machine.
The ordering field is now taken as a date where the value already is one, the raw value is preferred over the display value, and any remaining text is parsed with the invariant culture assuming UTC rather than by appending "Z", which also corrects values that carry their own offset. An ordering field that cannot be interpreted as a date and time now raises a ServiceNowApiException naming the field and the offending value, rather than a bare FormatException.
Reported as issue #25 and restated in issue #74.