Setting up the environment

Getting started

Before you can dive into working with the API, you first need to set up your development environment inside your code editor / IDE of choice.

For this guide, we will use Visual Studio 2022 and C# as the programming language of choice.

Requirements

  • Install the NuGet package Struct.App.Api.Client into your project.

  • Install the NuGet package Struct.App.Api.Models into your project.

  • Code editor / IDE.

Prerequisites


Setting the environment up

1

Create console application

Open Visual Studio 2022, and click 'Create a new project'. Search for Console, and select the Console app project with C# as the main programming language.

2

Install client nuget package

In your new project, install the Struct.App.Api.Client NuGet package.

Use the terminal command:

dotnet add package Struct.App.Api.Client --version 4.0.7

Or go to 'Tools' > 'NuGet Package Manager' > 'Manage NuGet Packages for Solution'. In the NuGet Package Manager, click on 'Browse', search for Struct.App.Api.Client, and install the latest version.

circle-info

Ensure you select the correct project on the right before installing the package.

3

Install model nuget package

To finalize the installation process, you need to install the Struct.App.Api.Models. You can do this by entering the following command in a terminal window within Visual Studio 2022:

dotnet add package Struct.App.Api.Models --version 4.0.7

Or by installing it via the Nuget Package manager just like in step 2.

4

Create a class that contain the StructApiClient field

Create a new class called ApiService. Inside this class, create a private field of type StructApiClient. Make the constructor instantiate the field.

using Struct.App.Api.Client;

namespace Struct.App.Api.Demo
{
    public class ApiService
    {
        private StructApiClient _apiClient;
        public ApiService()
        {
            _apiClient = new("your-pim-url-here", "your-api-key-here");
        }
    }
}

You will need to provide the URL to your PIM and the API key you created earlier.

triangle-exclamation
5

Create instance of ApiService inside Program.cs

Lastly, create an instance of ApiService inside the Main(string[] args) method inside the Program class. You will gain access to invoke methods within the ApiService.

using Struct.App.Api.Client;

namespace Struct.App.Api.Demo
{
    public class Program
    {
        static void Main(string[] args)
        {
            ApiService service = new ApiService();
            // You can now invoke methods inside the ApiService instance.
        }
    }
}

You're now ready to begin experimenting with the API through your ApiService instance. We recommend that you create methods inside the ApiService class which you then invoke through the Main(string[] args) method, inside the Program class.

Last updated