# 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

* You have generated an API key within your Struct PIM. If not, [see how to set it up here](https://docs.struct.com/tutorials/guides/how-to-use-struct-pims-api/how-to-set-up-and-edit-api-configurations).

***

### Setting the environment up

{% stepper %}
{% step %}

### Create console application

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2Ff2raSN2ZlUIcawpW4SA2%2Fimage.png?alt=media&#x26;token=9699aba8-4841-455a-a493-fa5a09b6aab8" alt=""><figcaption></figcaption></figure>

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.
{% endstep %}

{% step %}

### Install client nuget package

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

Use the terminal command:

```csharp
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.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FiUFykUjAjyKK9ipLw1gv%2Fimage.png?alt=media&#x26;token=b12b73fe-018b-4cb2-96f7-1f4b09d6d4e3" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Ensure you select the correct project on the right before installing the package.
{% endhint %}
{% endstep %}

{% step %}

### 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:

```csharp
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.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2Fy2GgpbScn6UjGcezJS7C%2Fimage.png?alt=media&#x26;token=fc617e49-44d3-4b05-8db1-856daf512beb" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 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.

```csharp
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.

{% hint style="danger" %} <mark style="color:$warning;">**Warning!**</mark> <mark style="color:$warning;">Your API key should be kept secret. Do not push any of the code you create in this guide to any public version control providers (eg Github, GitLab etc).</mark>
{% endhint %}
{% endstep %}

{% step %}

### 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`.

{% code overflow="wrap" %}

```csharp
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.
        }
    }
}
```

{% endcode %}
{% endstep %}
{% endstepper %}

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.
