https://github.com/panoramicdata/ServiceNow.Api
ServiceNow REST API nuget package
https://github.com/panoramicdata/ServiceNow.Api
Last synced: about 1 year ago
JSON representation
ServiceNow REST API nuget package
- Host: GitHub
- URL: https://github.com/panoramicdata/ServiceNow.Api
- Owner: panoramicdata
- License: mit
- Created: 2019-05-12T11:54:47.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-08-13T09:31:48.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T14:15:43.472Z (over 1 year ago)
- Language: C#
- Size: 30.1 MB
- Stars: 21
- Watchers: 6
- Forks: 18
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# ServiceNow.Api
[](https://www.nuget.org/packages/ServiceNow.Api/)
[](https://www.nuget.org/packages/ServiceNow.Api/)
[](https://opensource.org/licenses/MIT)
[](https://www.codacy.com/gh/panoramicdata/ServiceNow.Api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=panoramicdata/ServiceNow.Api&utm_campaign=Badge_Grade)
# Usage
To create a simple command line app that uses the ServiceNow REST API:
1. Create a .NET Core 7.0 Console project in Visual Studio
2. Ensure that you have specified <LangVersion>latest</LangVersion> in the csproj file, e.g.:
```` xml
Exe
net7.0
latest
enable
Recommended
latest-recommended
````
3. Edit Program.cs to be similar to the following:
```` C#
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 { "sys_id", "name" };
var jObjectResults = await serviceNowClient.GetAllByQueryAsync(
tableName,
query,
fields
).ConfigureAwait(false);
var modelResults = jObjectResults.ConvertAll(o => o.ToObject());
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; }
}
````