Schema
The DealCloud API allows you to query the schema of a given site. The SDK class provides access to the schema endpoints through the following methods:
Get Currencies
Client.Schema.GetCurrencies()
will return the currency codes of all enabled currencies in the site.
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
var currencies = dc.Schema.GetCurrencies().Result;
foreach (var ccy in currencies)
{
Console.WriteLine(ccy);
}
Will output:
GBP
USD
EUR
...etc
Get Users
Client.Schema.GetUsers(bool activeOnly = false)
will return all users in the site. Specifically, a list of User
objects. The argument: activeOnly
is a boolean that can be passed, if true, the function will only return active users.
Example:
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
var users = dc.Schema.GetUsers().Result;
/**
for only active users:
var users = dc.Schema.GetUsers(true).Result;
**/
foreach (var user in users)
{
Console.WriteLine($"{user.Name}: {user.Email}");
}
Will output:
User 1: user1@email.com
User 2: user2@email.com
User 3: user3@email.com
User 4: user4@email.com
...etc
Get Objects
Client.Schema.GetObjects()
will return all configured objects in the site. Specifically, a list of DcObject
objects.
Example:
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
var dcObjects = dc.Schema.GetObjects().Result;
foreach (var dcObject in dcObjects)
{
Console.WriteLine($"{dcObject.ApiName}: {dcObject.PluralName}, {dcObject.SingularName}");
}
Will output:
Company: Companies, Company
Contact: Contacts, Contact
CompanyAddress: Company Addresses, Company Address
...etc
Get Fields
There are three ways to access available fields in DealCloud.
1.Get all fields
Client.Schema.GetFields()
, with no arguments passed, returns all configured fields in the site.
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
var fields = dc.Schema.GetFields().Result;
2.Get fields for a given object
Client.Schema.GetFields(string objectId)
and Client.Schema.GetFields(int objectId)
, where objectId
is either the object API name, or the object ID, returns all configured fields for the desired object.
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
// will return all fields on the "Company" object.
var fields = dc.Schema.GetFields("Company").Result;
3.Get a specific field by ID
Client.Schema.GetField(int fieldId)
will retrieve a specific field by its field ID.
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
// will return the field with ID 1234
var fields = dc.Schema.GetField(1234).Result;
Get Schema
Client.Schema.GetSchema()
is a convenience method, that will return the full site schema in a single function.
The returned object is a DcSchema
object, which is a nested dictionary of objects and fields from the site.
using DealCloudSDK;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddJsonFile("environment_config.json")
.Build();
var dc = new Client(config);
var schema = dc.Schema.GetSchema().Result;
foreach (var obj in schema.Objects)
{
Console.WriteLine($"Showing object info for: {obj.Key}");
foreach (var field in obj.Value.Fields)
{
Console.WriteLine($"Field: {field.Value.Name}");
}
}
Will output:
Showing object info for: Company
Field: Company Name
Field: Business Description
...etc
Showing object info for: Contact
Field: Name
Field: First Name
Field: Last Name
Field: Email
...etc