BokaMera.API.Host

<back to all web services

CreateCustomField

Requires Authentication
Requires any of the roles:bookingsupplier-administrator-write, superadmin
The following routes are available for this service:
POST/customfieldsCreate a custom fieldCreates a new custom field, if an admin user is making the request, the user will be associated with the admin user's company.
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


class CustomFieldLookupResponse implements JsonSerializable
{
    public function __construct(
        /** @var int|null */
        public ?int $Id=null,
        /** @var bool|null */
        public ?bool $Active=null,
        /** @var int|null */
        public ?int $SortOrder=null,
        /** @var string|null */
        public ?string $Value=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Active'])) $this->Active = $o['Active'];
        if (isset($o['SortOrder'])) $this->SortOrder = $o['SortOrder'];
        if (isset($o['Value'])) $this->Value = $o['Value'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Active)) $o['Active'] = $this->Active;
        if (isset($this->SortOrder)) $o['SortOrder'] = $this->SortOrder;
        if (isset($this->Value)) $o['Value'] = $this->Value;
        return empty($o) ? new class(){} : $o;
    }
}

class CustomFieldServices implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $Id=0,
        /** @description Name of the service */
        // @ApiMember(Description="Name of the service")
        /** @var string|null */
        public ?string $Name=null,

        /** @description The image url of the service */
        // @ApiMember(Description="The image url of the service")
        /** @var string|null */
        public ?string $ImageUrl=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Name'])) $this->Name = $o['Name'];
        if (isset($o['ImageUrl'])) $this->ImageUrl = JsonConverters::from('string', $o['ImageUrl']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Name)) $o['Name'] = $this->Name;
        if (isset($this->ImageUrl)) $o['ImageUrl'] = JsonConverters::to('string', $this->ImageUrl);
        return empty($o) ? new class(){} : $o;
    }
}

class CustomFieldQueryResponse implements JsonSerializable
{
    public function __construct(
        /** @description Custom field id */
        // @ApiMember(Description="Custom field id")
        /** @var int */
        public int $Id=0,

        /** @description Reference to company that owns the custom field configuration */
        // @ApiMember(Description="Reference to company that owns the custom field configuration")
        /** @var string */
        public string $CompanyId='',

        /** @description Group id */
        // @ApiMember(Description="Group id")
        /** @var int|null */
        public ?int $GroupId=null,

        /** @description Field id */
        // @ApiMember(Description="Field id")
        /** @var int */
        public int $FieldId=0,

        /** @description Configuration name. Example: 'Number of persons'. */
        // @ApiMember(Description="Configuration name. Example: 'Number of persons'.")
        /** @var string|null */
        public ?string $Name=null,

        /** @description Field width. Example: 20 */
        // @ApiMember(Description="Field width. Example: 20")
        /** @var int */
        public int $Width=0,

        /** @description Column in database where to store the information. Example: 'TextField1' */
        // @ApiMember(Description="Column in database where to store the information. Example: 'TextField1'")
        /** @var string|null */
        public ?string $Column=null,

        /** @description Custom field description. Example: 'For how many persons is this booking?' */
        // @ApiMember(Description="Custom field description. Example: 'For how many persons is this booking?'")
        /** @var string|null */
        public ?string $Description=null,

        /** @description Data field of custom field. Valid values are: TextBox, ... Example: 'TextBox' */
        // @ApiMember(Description="Data field of custom field. Valid values are: TextBox, ... Example: 'TextBox'")
        /** @var string|null */
        public ?string $DataType=null,

        /** @description Default value of the field. Example: '3' */
        // @ApiMember(Description="Default value of the field. Example: '3'")
        /** @var string|null */
        public ?string $DefaultValue=null,

        /** @description Determines if the field is required to have a value or not */
        // @ApiMember(Description="Determines if the field is required to have a value or not")
        /** @var bool|null */
        public ?bool $IsMandatory=null,

        /** @description Error message shown to the user if the field data is required but not entered */
        // @ApiMember(Description="Error message shown to the user if the field data is required but not entered")
        /** @var string|null */
        public ?string $MandatoryErrorMessage=null,

        /** @description Max lenght of the field */
        // @ApiMember(Description="Max lenght of the field")
        /** @var int */
        public int $MaxLength=0,

        /** @description If the field should have multiple lines */
        // @ApiMember(Description="If the field should have multiple lines")
        /** @var bool|null */
        public ?bool $MultipleLineText=null,

        /** @description Regular expression used for validation of the field */
        // @ApiMember(Description="Regular expression used for validation of the field")
        /** @var string|null */
        public ?string $RegEx=null,

        /** @description Regular expression id for validation of the field */
        // @ApiMember(Description="Regular expression id for validation of the field")
        /** @var int|null */
        public ?int $RegExId=null,

        /** @description Error message shown if the regular expression validation failed */
        // @ApiMember(Description="Error message shown if the regular expression validation failed")
        /** @var string|null */
        public ?string $RegExErrorMessage=null,

        /** @description If the field is visible to the customer */
        // @ApiMember(Description="If the field is visible to the customer")
        /** @var bool|null */
        public ?bool $IsPublic=null,

        /** @description If the field should be hidden in lists */
        // @ApiMember(Description="If the field should be hidden in lists")
        /** @var bool|null */
        public ?bool $IsHidden=null,

        /** @description Table to which the field belongs */
        // @ApiMember(Description="Table to which the field belongs")
        /** @var string|null */
        public ?string $Table=null,

        /** @description The values to select from if Datatype is DropDown for this custom field */
        // @ApiMember(Description="The values to select from if Datatype is DropDown for this custom field")
        /** @var array<CustomFieldLookupResponse>|null */
        public ?array $Values=null,

        /** @description The services that is connected to the custom field */
        // @ApiMember(Description="The services that is connected to the custom field")
        /** @var array<CustomFieldServices>|null */
        public ?array $Services=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
        if (isset($o['GroupId'])) $this->GroupId = $o['GroupId'];
        if (isset($o['FieldId'])) $this->FieldId = $o['FieldId'];
        if (isset($o['Name'])) $this->Name = $o['Name'];
        if (isset($o['Width'])) $this->Width = $o['Width'];
        if (isset($o['Column'])) $this->Column = $o['Column'];
        if (isset($o['Description'])) $this->Description = $o['Description'];
        if (isset($o['DataType'])) $this->DataType = $o['DataType'];
        if (isset($o['DefaultValue'])) $this->DefaultValue = $o['DefaultValue'];
        if (isset($o['IsMandatory'])) $this->IsMandatory = $o['IsMandatory'];
        if (isset($o['MandatoryErrorMessage'])) $this->MandatoryErrorMessage = $o['MandatoryErrorMessage'];
        if (isset($o['MaxLength'])) $this->MaxLength = $o['MaxLength'];
        if (isset($o['MultipleLineText'])) $this->MultipleLineText = $o['MultipleLineText'];
        if (isset($o['RegEx'])) $this->RegEx = $o['RegEx'];
        if (isset($o['RegExId'])) $this->RegExId = $o['RegExId'];
        if (isset($o['RegExErrorMessage'])) $this->RegExErrorMessage = $o['RegExErrorMessage'];
        if (isset($o['IsPublic'])) $this->IsPublic = $o['IsPublic'];
        if (isset($o['IsHidden'])) $this->IsHidden = $o['IsHidden'];
        if (isset($o['Table'])) $this->Table = $o['Table'];
        if (isset($o['Values'])) $this->Values = JsonConverters::fromArray('CustomFieldLookupResponse', $o['Values']);
        if (isset($o['Services'])) $this->Services = JsonConverters::fromArray('CustomFieldServices', $o['Services']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
        if (isset($this->GroupId)) $o['GroupId'] = $this->GroupId;
        if (isset($this->FieldId)) $o['FieldId'] = $this->FieldId;
        if (isset($this->Name)) $o['Name'] = $this->Name;
        if (isset($this->Width)) $o['Width'] = $this->Width;
        if (isset($this->Column)) $o['Column'] = $this->Column;
        if (isset($this->Description)) $o['Description'] = $this->Description;
        if (isset($this->DataType)) $o['DataType'] = $this->DataType;
        if (isset($this->DefaultValue)) $o['DefaultValue'] = $this->DefaultValue;
        if (isset($this->IsMandatory)) $o['IsMandatory'] = $this->IsMandatory;
        if (isset($this->MandatoryErrorMessage)) $o['MandatoryErrorMessage'] = $this->MandatoryErrorMessage;
        if (isset($this->MaxLength)) $o['MaxLength'] = $this->MaxLength;
        if (isset($this->MultipleLineText)) $o['MultipleLineText'] = $this->MultipleLineText;
        if (isset($this->RegEx)) $o['RegEx'] = $this->RegEx;
        if (isset($this->RegExId)) $o['RegExId'] = $this->RegExId;
        if (isset($this->RegExErrorMessage)) $o['RegExErrorMessage'] = $this->RegExErrorMessage;
        if (isset($this->IsPublic)) $o['IsPublic'] = $this->IsPublic;
        if (isset($this->IsHidden)) $o['IsHidden'] = $this->IsHidden;
        if (isset($this->Table)) $o['Table'] = $this->Table;
        if (isset($this->Values)) $o['Values'] = JsonConverters::toArray('CustomFieldLookupResponse', $this->Values);
        if (isset($this->Services)) $o['Services'] = JsonConverters::toArray('CustomFieldServices', $this->Services);
        return empty($o) ? new class(){} : $o;
    }
}

class CustomFieldGroupValue implements JsonSerializable
{
    public function __construct(
        /** @var int|null */
        public ?int $SortOrder=null,
        /** @var string|null */
        public ?string $Value=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['SortOrder'])) $this->SortOrder = $o['SortOrder'];
        if (isset($o['Value'])) $this->Value = $o['Value'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->SortOrder)) $o['SortOrder'] = $this->SortOrder;
        if (isset($this->Value)) $o['Value'] = $this->Value;
        return empty($o) ? new class(){} : $o;
    }
}

// @ApiResponse(Description="Returned if there is a validation error on the input parameters", StatusCode=400)
// @ApiResponse(Description="Returned if the current user is not allowed to perform the action", StatusCode=401)
// @ValidateRequest(Validator="IsAuthenticated")
class CreateCustomField implements ICompany, JsonSerializable
{
    public function __construct(
        /** @description The company id, if empty will use the company id for the user you are logged in with. */
        // @ApiMember(Description="The company id, if empty will use the company id for the user you are logged in with.")
        /** @var string|null */
        public ?string $CompanyId=null,

        /** @description Field id */
        // @ApiMember(Description="Field id")
        /** @var int */
        public int $FieldId=0,

        /** @description Configuration name. Example: 'Number of persons'. */
        // @ApiMember(Description="Configuration name. Example: 'Number of persons'.", IsRequired=true)
        /** @var string */
        public string $Name='',

        /** @description Custom field description. Example: 'For how many persons is this booking?' */
        // @ApiMember(Description="Custom field description. Example: 'For how many persons is this booking?'", IsRequired=true)
        /** @var string */
        public string $Description='',

        /** @description Custom field icon id. Example: '1   House,2   Calendar,3   Building,4   Cart,5   Find,6   Blue flag,7   Green flag,8   Information,9   Lightning,10  Page edit,11  Pencil,12  Link,13  Star,14  User,15  Tick,16  Wrench,17  Clock' */
        // @ApiMember(Description="Custom field icon id. Example: '1   House,2   Calendar,3   Building,4   Cart,5   Find,6   Blue flag,7   Green flag,8   Information,9   Lightning,10  Page edit,11  Pencil,12  Link,13  Star,14  User,15  Tick,16  Wrench,17  Clock'", IsRequired=true)
        /** @var int */
        public int $IconId=0,

        /** @description Field width. Example: 20 */
        // @ApiMember(Description="Field width. Example: 20")
        /** @var int */
        public int $Width=0,

        /** @description Data field of custom field. Valid values are: TextBox, DropDown Example: 'TextBox' */
        // @ApiMember(Description="Data field of custom field. Valid values are: TextBox, DropDown Example: 'TextBox'")
        /** @var string|null */
        public ?string $Datatype=null,

        /** @description Default value of the field. Example: '3' */
        // @ApiMember(Description="Default value of the field. Example: '3'")
        /** @var string|null */
        public ?string $DefaultValue=null,

        /** @description Determines if the field is required to have a value or not. Default is false */
        // @ApiMember(Description="Determines if the field is required to have a value or not. Default is false")
        /** @var bool|null */
        public ?bool $IsMandatory=null,

        /** @description Error message shown to the user if the field data is required but not entered */
        // @ApiMember(Description="Error message shown to the user if the field data is required but not entered")
        /** @var string|null */
        public ?string $MandatoryErrorMessage=null,

        /** @description Max lenght of the field. Default is 500 */
        // @ApiMember(Description="Max lenght of the field. Default is 500", IsRequired=true)
        /** @var int */
        public int $MaxLength=0,

        /** @description If the field should have multiple lines. Defualt is false */
        // @ApiMember(Description="If the field should have multiple lines. Defualt is false")
        /** @var bool|null */
        public ?bool $MultipleLineText=null,

        /** @description Regular expression used for validation of the field */
        // @ApiMember(Description="Regular expression used for validation of the field")
        /** @var int|null */
        public ?int $RegExId=null,

        /** @description Error message shown if the regular expression validation failed */
        // @ApiMember(Description="Error message shown if the regular expression validation failed")
        /** @var string|null */
        public ?string $RegExErrorMessage=null,

        /** @description If the field is visible to the customer. Default is true */
        // @ApiMember(Description="If the field is visible to the customer. Default is true")
        /** @var bool|null */
        public ?bool $IsPublic=null,

        /** @description If the field should be hidden in lists. Default is false */
        // @ApiMember(Description="If the field should be hidden in lists. Default is false")
        /** @var bool|null */
        public ?bool $IsHidden=null,

        /** @description The values to select from if Datatype is DropDown for this custom field */
        // @ApiMember(Description="The values to select from if Datatype is DropDown for this custom field")
        /** @var array<CustomFieldGroupValue>|null */
        public ?array $Values=null,

        /** @description The services that is connected to the custom field. If null it will be connected to all services. */
        // @ApiMember(Description="The services that is connected to the custom field. If null it will be connected to all services.")
        /** @var array<CustomFieldServices>|null */
        public ?array $Services=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
        if (isset($o['FieldId'])) $this->FieldId = $o['FieldId'];
        if (isset($o['Name'])) $this->Name = $o['Name'];
        if (isset($o['Description'])) $this->Description = $o['Description'];
        if (isset($o['IconId'])) $this->IconId = $o['IconId'];
        if (isset($o['Width'])) $this->Width = $o['Width'];
        if (isset($o['Datatype'])) $this->Datatype = $o['Datatype'];
        if (isset($o['DefaultValue'])) $this->DefaultValue = $o['DefaultValue'];
        if (isset($o['IsMandatory'])) $this->IsMandatory = $o['IsMandatory'];
        if (isset($o['MandatoryErrorMessage'])) $this->MandatoryErrorMessage = $o['MandatoryErrorMessage'];
        if (isset($o['MaxLength'])) $this->MaxLength = $o['MaxLength'];
        if (isset($o['MultipleLineText'])) $this->MultipleLineText = $o['MultipleLineText'];
        if (isset($o['RegExId'])) $this->RegExId = $o['RegExId'];
        if (isset($o['RegExErrorMessage'])) $this->RegExErrorMessage = $o['RegExErrorMessage'];
        if (isset($o['IsPublic'])) $this->IsPublic = $o['IsPublic'];
        if (isset($o['IsHidden'])) $this->IsHidden = $o['IsHidden'];
        if (isset($o['Values'])) $this->Values = JsonConverters::fromArray('CustomFieldGroupValue', $o['Values']);
        if (isset($o['Services'])) $this->Services = JsonConverters::fromArray('CustomFieldServices', $o['Services']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
        if (isset($this->FieldId)) $o['FieldId'] = $this->FieldId;
        if (isset($this->Name)) $o['Name'] = $this->Name;
        if (isset($this->Description)) $o['Description'] = $this->Description;
        if (isset($this->IconId)) $o['IconId'] = $this->IconId;
        if (isset($this->Width)) $o['Width'] = $this->Width;
        if (isset($this->Datatype)) $o['Datatype'] = $this->Datatype;
        if (isset($this->DefaultValue)) $o['DefaultValue'] = $this->DefaultValue;
        if (isset($this->IsMandatory)) $o['IsMandatory'] = $this->IsMandatory;
        if (isset($this->MandatoryErrorMessage)) $o['MandatoryErrorMessage'] = $this->MandatoryErrorMessage;
        if (isset($this->MaxLength)) $o['MaxLength'] = $this->MaxLength;
        if (isset($this->MultipleLineText)) $o['MultipleLineText'] = $this->MultipleLineText;
        if (isset($this->RegExId)) $o['RegExId'] = $this->RegExId;
        if (isset($this->RegExErrorMessage)) $o['RegExErrorMessage'] = $this->RegExErrorMessage;
        if (isset($this->IsPublic)) $o['IsPublic'] = $this->IsPublic;
        if (isset($this->IsHidden)) $o['IsHidden'] = $this->IsHidden;
        if (isset($this->Values)) $o['Values'] = JsonConverters::toArray('CustomFieldGroupValue', $this->Values);
        if (isset($this->Services)) $o['Services'] = JsonConverters::toArray('CustomFieldServices', $this->Services);
        return empty($o) ? new class(){} : $o;
    }
}

PHP CreateCustomField DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv

HTTP + JSV

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /customfields HTTP/1.1 
Host: api.bokamera.se 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	CompanyId: 00000000-0000-0000-0000-000000000000,
	FieldId: 0,
	Name: String,
	Description: String,
	IconId: 0,
	Width: 0,
	Datatype: String,
	DefaultValue: String,
	IsMandatory: False,
	MandatoryErrorMessage: String,
	MaxLength: 0,
	MultipleLineText: False,
	RegExId: 0,
	RegExErrorMessage: String,
	IsPublic: False,
	IsHidden: False,
	Values: 
	[
		{
			SortOrder: 0,
			Value: String
		}
	],
	Services: 
	[
		{
			Id: 0,
			Name: String
		}
	]
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	Id: 0,
	GroupId: 0,
	FieldId: 0,
	Name: String,
	Width: 0,
	Column: String,
	Description: String,
	DataType: String,
	DefaultValue: String,
	IsMandatory: False,
	MandatoryErrorMessage: String,
	MaxLength: 0,
	MultipleLineText: False,
	RegEx: String,
	RegExId: 0,
	RegExErrorMessage: String,
	IsPublic: False,
	IsHidden: False,
	Table: String,
	Values: 
	[
		{
			Id: 0,
			Active: False,
			SortOrder: 0,
			Value: String
		}
	],
	Services: 
	[
		{
			Id: 0,
			Name: String
		}
	]
}