Table of Contents

Class RevitServerApi

Namespace
RevitServerNet
Assembly
RevitServerNet.dll

Main class for working with Revit Server REST API

public class RevitServerApi

Inheritance

Inherited Members

Extension Methods

Constructors

RevitServerApi(string, string, bool, string)

Initializes a new instance of RevitServerApi

public RevitServerApi(string host, string userName, bool useHttps = false, string serverVersion = "2019")

Parameters

host string

Revit Server host (e.g. "localhost" or IP address)

userName string

User name for API requests

useHttps bool

Use HTTPS (default: false)

serverVersion string

Server version (default: "2019")

Properties

BaseUrl

Base URL for API

public string BaseUrl { get; }

Property Value

string

Timeout

Time limit of one REST request, from sending it to reading the whole response. When it elapses the request is aborted and a RevitServerNet.RevitServerApiException is thrown; System.Threading.Timeout.InfiniteTimeSpan means no limit. null (the default) keeps the behaviour of the platform, as before this property existed: on .NET 6/8 HttpWebRequest ends a request after 100 s, on .NET Framework its async calls have no limit.

public TimeSpan? Timeout { get; set; }

Property Value

TimeSpan?

UserName

User name

public string UserName { get; }

Property Value

string

Methods

DeleteAsync(string, Dictionary<string, string>)

Performs DELETE request to API

public Task<string> DeleteAsync(string command, Dictionary<string, string> additionalHeaders = null)

Parameters

command string

API command

additionalHeaders Dictionary<string, string>

Additional headers

Returns

Task<string>

JSON response from server

DeleteAsync(string, Dictionary<string, string>, CancellationToken)

Performs DELETE request to API; the request is aborted when cancellationToken is cancelled

public Task<string> DeleteAsync(string command, Dictionary<string, string> additionalHeaders, CancellationToken cancellationToken)

Parameters

command string
additionalHeaders Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<string>

EncodePath(string)

Encodes path in API format: replaces separators with |, then percent-encodes every folder/model name (segment between |) with System.Uri.EscapeDataString(System.String). The | separator itself is kept as is.

public static string EncodePath(string path)

Parameters

path string

Path to file or folder with raw (unescaped) names, e.g. "|#Archive|Model.rvt"

Returns

string

URL path segment ready to put into a command, e.g. "|%23Archive|Model.rvt"

GetAsync(string, Dictionary<string, string>)

Performs GET request to API

public Task<string> GetAsync(string command, Dictionary<string, string> additionalHeaders = null)

Parameters

command string

API command

additionalHeaders Dictionary<string, string>

Additional headers

Returns

Task<string>

JSON response from server

GetAsync(string, Dictionary<string, string>, CancellationToken)

Performs GET request to API; the request is aborted when cancellationToken is cancelled

public Task<string> GetAsync(string command, Dictionary<string, string> additionalHeaders, CancellationToken cancellationToken)

Parameters

command string
additionalHeaders Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<string>

PostAsync(string, string, Dictionary<string, string>)

Performs POST request to API

public Task<string> PostAsync(string command, string data = null, Dictionary<string, string> additionalHeaders = null)

Parameters

command string

API command

data string

Data to send

additionalHeaders Dictionary<string, string>

Additional headers

Returns

Task<string>

JSON response from server

PostAsync(string, string, Dictionary<string, string>, CancellationToken)

Performs POST request to API; the request is aborted when cancellationToken is cancelled

public Task<string> PostAsync(string command, string data, Dictionary<string, string> additionalHeaders, CancellationToken cancellationToken)

Parameters

command string
data string
additionalHeaders Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<string>

PutAsync(string, string, Dictionary<string, string>)

Performs PUT request to API

public Task<string> PutAsync(string command, string data = null, Dictionary<string, string> additionalHeaders = null)

Parameters

command string

API command

data string

Data to send

additionalHeaders Dictionary<string, string>

Additional headers

Returns

Task<string>

JSON response from server

PutAsync(string, string, Dictionary<string, string>, CancellationToken)

Performs PUT request to API; the request is aborted when cancellationToken is cancelled

public Task<string> PutAsync(string command, string data, Dictionary<string, string> additionalHeaders, CancellationToken cancellationToken)

Parameters

command string
data string
additionalHeaders Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<string>