CSM 10.5 Documentation

Home

Using Swagger Code Generation

Use swagger-codegen to generate client code.

Important: Changes to the Cherwell REST API may require you to regenerate Swagger code after you upgrade to a new version of CSM. If you receive errors in your API calls after you upgrade, follow the guidance in this article to regenerate client code.

Follow this process:

  1. Download the swagger-codegen JAR from the Maven website.
  2. Create a .bat file similar to the following example:
                                        java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i
    http://localhost/CherwellApi/swagger/docs/all -l csharp -o cherwell/client/csharp
                                    
  3. Place the .bat file in the same level as the Swagger code gen modules directory.
    The example script creates output in a cherwell/client/csharp directory at the same level where the .bat file is placed.
  4. Add the generated code from the output directory to your project and reference it.
You can now call the generated Swagger code for CSM.

Sample Authenticated Request

                                var service = new ServiceApi(baseuri);
var tokenResponse = service.ServiceToken("password", clientid, "", username, password, "", "Internal");
var searchesApi = new SearchesApi(Baseuri);
searchesApi.DefaultHeader.Add("Authorization", "Bearer " + tokenResponse.AccessToken);
var searchItemResponse = searchesApi.SearchesGetSearchItemsV1(null);

                            


Was this article useful?