# API ForeignKeys

## **Specs**

| Label                     | Value                         |
| ------------------------- | ----------------------------- |
| **Version**               | 0.1.0 (updated on 2025-02-11) |
| **Developer**             | Labii Inc.                    |
| **Type**                  | Column                        |
| **Support Configuration** | Yes                           |
| **Support Readonly view** | Yes                           |
| **Support Edit view**     | Yes                           |
| **Support Form view**     | Yes                           |
| **Support Default value** | Yes                           |
| **Support Import**        | Yes                           |
| **Allow multiple**        | Yes                           |

## Overview

The Labii API ForeignKeys Widget extends the functionality of the API ForeignKey Widget by allowing users to select multiple options from an API-fetched dropdown list. Like the API ForeignKey Widget, it dynamically retrieves data from a specified API URL, enabling seamless integration of external resources into Labii. This widget is ideal for workflows that require linking multiple external references to a single record, providing greater flexibility and efficiency in managing interconnected data within Labii.

## Use case

* Display lot numbers of potential orders from 3rd party vendor.

## Configuration

To enable the widget's functionality, it requires the provision of options.

* **Bearer Token** - Bearer Token or any other authorization string. Bearer Tokens are the predominant type of access token used with OAuth 2.0. For example: Bearer eyJraWQiOiIy
* **URL** - The URL to download list of items.
* **Search Prefix** - The prefix to search for list of items. Default to empty.
* **Method** - The API method to download list of items. Default to GET.
* **Results Key** - The key to extract results from the API response. Default to results.
* **SID Key** - The key to extract SID/ID from the API response. Default to id.
* **Name Key** - The key to extract Name from the API response. Default to name.
* **Link** - Link to the detail page of the record. Use {SID} to replace with the record's sid/id.

### Example

```json
{
    "url": "http://127.0.0.1:8080/vendors/",
    "method": "get",
    "sid_key": "id",
    "name_key": "name",
    "results_key": "results",
    "authorization": "Bearer xxx",
    "search_prefix": "name__icontains"
}
```

## Views

See the interface of the widget in the following views.

### **Readonly view**

Readonly view display the values of the column.

<figure><img src="/files/gMzT8eqaHiLdvrXvHUoA" alt=""><figcaption></figcaption></figure>

### **Edit view**

The Edit view is the interface that allows you to modify the value.

Edit view is not supported for this widget.

<figure><img src="/files/aMvqWlqq4RWhdFfufdpt" alt=""><figcaption></figcaption></figure>

### **Form view**

The Form view is the field integrated into the add form for collecting values when creating a new record.

Form view is identical to the Edit view.

## Data

Each widget in Labii stores data in a unique manner; refer below to understand how data from this widget is stored.

### Data format

JSON object with the keys of `sid` and `name`.

```json
{"sid": "", "name": ""}
```

### **Default value**

The Default Value field within the column allows you to specify the default value when a record is created.

Default value shall be json object with keys of sid and name.

### **Import value**

The Import Value is the value you need to include in your Excel table for it to be imported into Labii.

Import value shall be json object with keys of sid and name.


---

# 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.labii.com/widgets/column-widgets/integration/dropdown/api-foreignkeys.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.
