C# Example: Get Search Items
The following example shows how to get search items using C#.
Run Swagger Code Generation before attempting to modify the code so that you do not receive reference errors.
Copy
using IO.Swagger.Api;
namespace Trebuchet.WebApi.IntegrationTests.ExamplesForCustomers.Searches
{
public class GetSearchItems
{
public void GetSearchItemsByAssociationAndScope()
{
//Get an access token using CSM credentials
var serviceApi = new ServiceApi("http://server/CherwellApi/");
var tokenResponse = serviceApi.ServiceToken("password", "your client id", null,"CSDAdmin", "CSDAdmin", null, "Internal");
//Create a new Searches api object and add the default header
var searchesApi = new SearchesApi("http://server/CherwellApi/");
searchesApi.Configuration.AddDefaultHeader("Authorization","Bearer " + tokenResponse.AccessToken);
//Create a new Business Object api object and add the default header
var businessObjectApi = new BusinessObjectApi("http://server/CherwellApi/");
businessObjectApi.Configuration.AddDefaultHeader("Authorization","Bearer " + tokenResponse.AccessToken);
//Get the Business Object summary by name. This returns the Business Object ID
var businessObjectSummaryByName = businessObjectApi.BusinessObjectGetBusinessObjectSummaryByNameV1("Incident");
var searchItemResponse = searchesApi.SearchesGetSearchItemsByAssociationScopeV1(businessObjectSummaryByName[0].BusObId, "Global", null);
}
}
}