# 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}](/api-reference/endpoints/globallists.md#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}](/api-reference/endpoints/globallists.md#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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.struct.com/tutorials/guides/how-to-use-struct-pims-api/use-of-global-list-endpoints.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
