# Use of Global list endpoints

### Updating a global list

{% tabs %}
{% tab title="HTTP" %}
**PUT** /v1/GlobalLists/{uid}/values
{% endtab %}

{% tab title="Request body (json)" %}

```
[
  {
    "Uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "SortOrder": 0,
    "Value": "string"
  }
]
```

{% endtab %}
{% endtabs %}

When updating a global list there are a large amount of changes that can be made on each respective list. In this case we are updating the values of a global list.

In the following example we will set everything up so that you can get an idea of how to use the API.

Retrieving a global list along with its values.

{% code title="C#" overflow="wrap" %}

```csharp
GlobalList existingGlobalList = _apiClient.GlobalLists.GetGlobalList("Suppliers");
```

{% endcode %}

The `GetGlobalList` method sends an HTTP request to the [/v1/GlobalLists/ByAlias/{alias}](https://docs.struct.com/api-reference/endpoints/globallists#get-v1-globallists-byalias-alias) endpoint. As alias we use "Suppliers" in order to retrieve all the global lists under the alias.&#x20;

Alternatively you can use the [/v1/GlobalLists/{uid}](https://docs.struct.com/api-reference/endpoints/globallists#get-v1-globallists-uid) endpoint instead if you know the uid of the global list you are looking for.&#x20;

After having fetched the global list we can now follow up with also retrieving its values.

{% code title="C#" overflow="wrap" %}

```csharp

Dictionary<string, GlobalListValue<SuppliersGlobalListModel>> globalListValues = _apiClient.GlobalLists.GetGlobalListValues<SuppliersGlobalListModel>(existingGlobalList.Uid).GlobalListValues.ToDictionary(x => x.Value.SupplierId);
```

{% endcode %}

Now we need some values to update the global lists with. In this example we use the model `SuppliersGlobalListModel` to set up the data that we want to update our PIM with.

{% code title="C#" overflow="wrap" %}

```csharp
List<SuppliersGlobalListModel> newData = new List<SuppliersGlobalListModel>
{
    new SuppliersGlobalListModel { SupplierId = "100", Name = "Supplier D (Updated)", Phone = "555-0101", Email = "contact@supplier-D.com" },
    new SuppliersGlobalListModel { SupplierId = "83", Name = "Supplier B (Updated)", Phone = "555-0303", Email = "support@supplier-B.com" },
};
```

{% endcode %}

From here we proceed with updating the global lists, but only if the `SupplierId` from `newData` matches an entry in `globalListValues`.

{% code title="C#" overflow="wrap" %}

```csharp
var globalListValuesToUpdate = new List<GlobalListValue<SuppliersGlobalListModel>>();

foreach (var newSupplierData in newData)
{
    if (globalListValues.TryGetValue(newSupplierData.SupplierId, out var existingGlobalListValue))
    {
        existingGlobalListValue.Value.Name = newSupplierData.Name;
        existingGlobalListValue.Value.Phone = newSupplierData.Phone;
        existingGlobalListValue.Value.Email = newSupplierData.Email;

        globalListValuesToUpdate.Add(existingGlobalListValue);
    }
}
```

{% endcode %}

With them now updated we can proceed to update the values of the global list in the PIM with the changes.

{% code title="C#" overflow="wrap" %}

```csharp
    _apiClient.GlobalLists.UpdateGlobalListValues<SuppliersGlobalListModel>            (existingGlobalList.Uid, globalListValuesToUpdate.ToList());

```

{% endcode %}
