BokaMera.API.Host

<back to all web services

CreateApiKey

Requires Authentication
Requires any of the roles:bookingsupplier-administrator-write, superadmin
The following routes are available for this service:
POST/apikeysCreate a new API key for the logged in user's companyGenerates a new API key for the company of the currently logged in user and returns it. A company administrator can only create keys for their own 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 ApiKeyResponse implements JsonSerializable
{
    public function __construct(
        /** @description The company the API key belongs to */
        // @ApiMember(Description="The company the API key belongs to")
        /** @var string */
        public string $CompanyId='',

        /** @description The API key value to send in the x-api-key header */
        // @ApiMember(Description="The API key value to send in the x-api-key header")
        /** @var string */
        public string $ApiKey='',

        /** @description Whether the key is active */
        // @ApiMember(Description="Whether the key is active")
        /** @var bool|null */
        public ?bool $Active=null,

        /** @description When the key was created */
        // @ApiMember(Description="When the key was created")
        /** @var DateTime */
        public DateTime $CreatedDate=new DateTime(),

        /** @description When the key expires, if ever */
        // @ApiMember(Description="When the key expires, if ever")
        /** @var DateTime|null */
        public ?DateTime $ExpiryDate=null,

        /** @description Contact email registered for the key */
        // @ApiMember(Description="Contact email registered for the key")
        /** @var string */
        public string $ContactEmail='',

        /** @description Free text notes for the key */
        // @ApiMember(Description="Free text notes for the key")
        /** @var string */
        public string $Notes='',

        /** @description Comma separated list of IP addresses the key is restricted to, if any */
        // @ApiMember(Description="Comma separated list of IP addresses the key is restricted to, if any")
        /** @var string */
        public string $AllowedIpAddresses=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
        if (isset($o['ApiKey'])) $this->ApiKey = $o['ApiKey'];
        if (isset($o['Active'])) $this->Active = $o['Active'];
        if (isset($o['CreatedDate'])) $this->CreatedDate = JsonConverters::from('DateTime', $o['CreatedDate']);
        if (isset($o['ExpiryDate'])) $this->ExpiryDate = JsonConverters::from('DateTime', $o['ExpiryDate']);
        if (isset($o['ContactEmail'])) $this->ContactEmail = $o['ContactEmail'];
        if (isset($o['Notes'])) $this->Notes = $o['Notes'];
        if (isset($o['AllowedIpAddresses'])) $this->AllowedIpAddresses = $o['AllowedIpAddresses'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
        if (isset($this->ApiKey)) $o['ApiKey'] = $this->ApiKey;
        if (isset($this->Active)) $o['Active'] = $this->Active;
        if (isset($this->CreatedDate)) $o['CreatedDate'] = JsonConverters::to('DateTime', $this->CreatedDate);
        if (isset($this->ExpiryDate)) $o['ExpiryDate'] = JsonConverters::to('DateTime', $this->ExpiryDate);
        if (isset($this->ContactEmail)) $o['ContactEmail'] = $this->ContactEmail;
        if (isset($this->Notes)) $o['Notes'] = $this->Notes;
        if (isset($this->AllowedIpAddresses)) $o['AllowedIpAddresses'] = $this->AllowedIpAddresses;
        return empty($o) ? new class(){} : $o;
    }
}

// @ApiResponse(Description="Returned if the current user is not authenticated", StatusCode=401)
// @ApiResponse(Description="Returned if the current user does not have the required role", StatusCode=403)
class CreateApiKey implements ICompany, JsonSerializable
{
    public function __construct(
        /** @description The company to create the API key for. Defaults to the logged in user's company. Only a SuperAdmin may specify a company other than their own; for other roles this value is ignored. */
        // @ApiMember(Description="The company to create the API key for. Defaults to the logged in user's company. Only a SuperAdmin may specify a company other than their own; for other roles this value is ignored.")
        /** @var string|null */
        public ?string $CompanyId=null,

        /** @description Optional contact email to register for the key. Defaults to the logged in user's email. */
        // @ApiMember(Description="Optional contact email to register for the key. Defaults to the logged in user's email.")
        /** @var string */
        public string $ContactEmail='',

        /** @description Optional free text note for the key. */
        // @ApiMember(Description="Optional free text note for the key.")
        /** @var string */
        public string $Notes=''
    ) {
    }

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

PHP CreateApiKey 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 /apikeys HTTP/1.1 
Host: api.bookmore.com 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	CompanyId: 00000000-0000-0000-0000-000000000000,
	ContactEmail: String,
	Notes: String
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	Active: False,
	ExpiryDate: "0001-01-01T00:00:00",
	ContactEmail: String,
	Notes: String,
	AllowedIpAddresses: String
}