> ## Documentation Index
> Fetch the complete documentation index at: https://docs.auxia.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get DataFields

> API for getting DataFields via API.

This document provides a guide and overview for the GetDataFields RPC, which allows you to get DataFields directly via API.

## API Definition

```url theme={null}
POST https://apis.auxia.io/v1/GetDataFields
```

## Entities

### DataFieldParams

```
message DataFieldParams {
  // Required
  oneof params {
    UserAttributeDataFieldParams user_attribute_data_field_params = 1;
    TreatmentDataFieldParams treatment_data_field_params = 2;
    EventDataFieldParams event_data_field_params = 3;
  }

  // User Attribute Params
  message UserAttributeDataFieldParams{
    // Required
    string property_name = 1;
  }

  // Treatment Interaction Metrics Params
  message TreatmentDataFieldParams {
    // Required
    TreatmentInteractionType treatment_interaction_type = 1;

    // Optional.
    // Aggregate interaction counts by either treatment ID or surface.
    oneof aggregate_by {
      string treatment_id = 2;

      string surface_id = 3;

      // Surface name (e.g., "HOME_SCREEN"). Resolved to surface ID internally.
      string surface_name = 10;
    }

    bool is_distinct_interaction = 4;

    // Required
    oneof aggregation {
      DailyCountAggregation daily_count_aggregation = 5;
      FirstTimestampAggregation first_timestamp_aggregation = 6;
      LatestTimestampAggregation latest_timestamp_aggregation = 7;
      DaysSinceFirstTimestampAggregation days_since_first_timestamp_aggregation = 8;
      DaysSinceLastTimestampAggregation days_since_last_timestamp_aggregation = 9;
    }

    enum TreatmentInteractionType {
      TREATMENT_INTERACTION_TYPE_UNSPECIFIED = 0;
      SENT = 1;
      VIEWED = 2;
      CLICKED = 3;
      SNOOZED = 4;
      DISMISSED = 5;
      CTA_COMPLETED = 6;
      SWIPE = 7;
    }
  }

  // Event Metric Params
  message EventDataFieldParams {
    // Required
    string event_schema_name = 1;
    // Optional
    map<string, PropertyValuePb> property_value_by_property_name = 2;

    // Required
    oneof aggregation {
      DailyCountAggregation daily_count_aggregation = 3;
      FirstTimestampAggregation first_timestamp_aggregation = 4;
      LatestTimestampAggregation latest_timestamp_aggregation = 5;
      DaysSinceFirstTimestampAggregation days_since_first_timestamp_aggregation = 6;
      DaysSinceLastTimestampAggregation days_since_last_timestamp_aggregation = 7;
    }
  }

  // Property Value
  message PropertyValuePb {
    oneof property_value {
      int64 long_value = 1;
      double double_value = 2;
      string string_value = 3;
      bool boolean_value = 4;
      google.protobuf.Timestamp timestamp_value = 5;
    }
  }
}
message FirstTimestampAggregation {}

message LatestTimestampAggregation {}

message DaysSinceFirstTimestampAggregation {}

message DaysSinceLastTimestampAggregation {}

```

### ResolvedDataFieldPb

```
message ResolvedDataFieldPb {
  int64 data_field_id = 1;
  DataFieldParams data_field_params = 2;
  string data_field_type = 3;
}

```

## GetDataFields

### API to get DataField Parameters

```
message GetDataFieldsByParamsRequest {
  // Required
  string project_id = 1;

  // Required
  repeated DataFieldParams data_field_params = 2;
}

message GetDataFieldsByParamsResponse {
  repeated ResolvedDataFieldPb data_fields = 1;
}

```

### Sample cURL Request

```
curl --location --request POST 'https://apis.auxia.io/v1/GetDataFields' \
--header 'Content-Type: application/json' \
--header 'x-api-key: API_KEY' \
--data-raw '{
  "projectId": "PROJECT_ID",
  "dataFieldParams": [
    {
      "treatmentDataFieldParams": {
        "treatmentId": "TREATMENT_ID",
        "treatmentInteractionType": "VIEWED",
        "dailyCountAggregation": {
          "windowName": "LAST_1D"
        }
      }
    },
    {
      "treatmentDataFieldParams": {
        "surfaceName": "HOME_SCREEN",
        "treatmentInteractionType": "VIEWED",
        "dailyCountAggregation": {
          "windowName": "LAST_1D"
        }
      }
    },
    {
      "eventDataFieldParams": {
        "eventSchemaName": "Stream Finished",
        "propertyValueByPropertyName": {
          "duration_seconds": {
            "longValue": 1800
          }
        },
        "dailyCountAggregation": {
          "windowName": "LAST_14D"
        }
      }
    },
    {
      "userAttributeDataFieldParams": {
        "propertyName": "signup_completed_timestamp_seconds"
      }
    }
  ]
}'

```

### Sample Response

```
{
  "dataFields": [
    {
      "dataFieldId": "1",
      "dataFieldParams": {
        "treatmentDataFieldParams": {
          "treatmentInteractionType": "VIEWED",
          "treatmentId": "TREATMENT_ID",
          "dailyCountAggregation": {
            "windowName": "LAST_1D"
          }
        }
      },
      "dataFieldType": "INTEGER"
    },
    {
      "dataFieldId": "2",
      "dataFieldParams": {
        "treatmentDataFieldParams": {
          "treatmentInteractionType": "VIEWED",
          "surfaceName": "HOME_SCREEN",
          "dailyCountAggregation": {
            "windowName": "LAST_1D"
          }
        }
      },
      "dataFieldType": "INTEGER"
    },
    {
      "dataFieldId": "3",
      "dataFieldParams": {
        "eventDataFieldParams": {
          "eventSchemaName": "Stream Finished",
          "propertyValueByPropertyName": {
            "duration_seconds": {
              "longValue": 1800
            }
          },
          "dailyCountAggregation": {
            "windowName": "LAST_14D"
          }
        }
      },
      "dataFieldType": "INTEGER"
    },
    {
      "dataFieldId": "4",
      "dataFieldParams": {
        "userAttributeDataFieldParams": {
          "propertyName": "signup_completed_timestamp_seconds"
        }
      },
      "dataFieldType": "TIMESTAMP_SECONDS"
    }
  ]
}

```
