Create a Field
POSThttps://euwest.api.elasticpath.com/v2/fields
- For Commerce, this endpoint creates a field.
- For Product Experience Manager, this endpoint creates an attribute.
Request
- application/json
Bodyrequired
data object
Responses
- 201
- 422
- 500
Created
- application/json
- Schema
- Example (auto)
- default
Schema
data object
{
"data": {
"id": "00000000-0000-0000-0000-000000000000",
"type": "string",
"field_type": "string",
"slug": "string",
"name": "string",
"description": "string",
"required": true,
"enabled": true,
"omit_null": true,
"validation_rules": [
{
"type": "enum",
"options": [
"string"
],
"to": "customer"
}
],
"meta": {
"owner": "enum",
"timestamps": {
"created_at": "2023-10-11T13:02:25.293Z",
"updated_at": "2023-10-11T13:02:25.293Z"
}
},
"links": {
"self": "https://euwest.api.elasticpath.com/v2/flows/3cf3ad3f-b12c-4a08-a6ab-05e6aab0122c/fields/c1c788d1-f1c7-4b90-938f-f158f3353c66"
},
"relationships": {
"flow": {
"data": {
"id": "00000000-0000-0000-0000-000000000000",
"type": "flow"
}
}
}
}
}
{
"data": {
"type": "field",
"name": "Product Rating",
"slug": "product-rating",
"field_type": "integer",
"validation_rules": [
{
"type": "between",
"options": {
"from": 1,
"to": 5
}
}
],
"description": "Average rating as given by our users",
"required": false,
"default": 0,
"enabled": true,
"order": 1,
"omit_null": false,
"relationships": {
"flow": {
"data": {
"type": "flow",
"id": "e4145c27-aba1-46af-81a3-58f5e1cf7f15"
}
}
}
}
}
Bad request. The request failed validation.
- application/json
- Schema
- Example (auto)
- missing-name
Schema
errors Error[]required
{
"errors": [
{
"status": 500,
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"title": "Validation Error",
"status": 400,
"detail": "data.attributes.name: \"name\" is required"
}
]
}
Internal server error. There was a system failure in the platform.
- application/json
- Schema
- Example (auto)
- internal-server-error
Schema
errors Error[]required
{
"errors": [
{
"status": 500,
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"status": 500,
"title": "Internal Server Error",
"detail": "There was an internal server error, you can report with your request id.",
"request_id": "635da56d-75a1-43cd-b696-7ab119756b3a"
}
]
}
Authorization: http
name: bearerAuthtype: httpscheme: bearer
- csharp
- curl
- dart
- go
- http
- java
- javascript
- kotlin
- c
- nodejs
- objective-c
- ocaml
- php
- powershell
- python
- r
- ruby
- rust
- shell
- swift
- HTTPCLIENT
- RESTSHARP
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://euwest.api.elasticpath.com/v2/fields");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <token>");
var content = new StringContent("{\n \"data\": {\n \"default\": 0,\n \"description\": \"string\",\n \"enabled\": true,\n \"field_type\": \"string\",\n \"name\": \"string\",\n \"order\": 0,\n \"relationships\": {\n \"flow\": {\n \"data\": {\n \"id\": \"00000000-0000-0000-0000-000000000000\",\n \"type\": \"flow\"\n }\n }\n },\n \"required\": true,\n \"slug\": \"string\",\n \"type\": \"string\",\n \"validation_rules\": [\n {\n \"type\": \"enum\",\n \"options\": [\n \"string\"\n ],\n \"to\": \"customer\"\n }\n ]\n }\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
ResponseClear