Northwind Web Services

<back to all web services

GetCustomerDetails

Customers
The following routes are available for this service:
All Verbs/customers/{Id}
<?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};


// @DataContract
class Customer implements JsonSerializable
{
    public function __construct(
        // @DataMember
        /** @var string */
        public string $id='',

        // @DataMember
        /** @var string */
        public string $companyName='',

        // @DataMember
        /** @var string */
        public string $contactName='',

        // @DataMember
        /** @var string */
        public string $contactTitle='',

        // @DataMember
        /** @var string */
        public string $address='',

        // @DataMember
        /** @var string */
        public string $city='',

        // @DataMember
        /** @var string */
        public string $region='',

        // @DataMember
        /** @var string */
        public string $postalCode='',

        // @DataMember
        /** @var string */
        public string $country='',

        // @DataMember
        /** @var string */
        public string $phone='',

        // @DataMember
        /** @var string */
        public string $fax=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['companyName'])) $this->companyName = $o['companyName'];
        if (isset($o['contactName'])) $this->contactName = $o['contactName'];
        if (isset($o['contactTitle'])) $this->contactTitle = $o['contactTitle'];
        if (isset($o['address'])) $this->address = $o['address'];
        if (isset($o['city'])) $this->city = $o['city'];
        if (isset($o['region'])) $this->region = $o['region'];
        if (isset($o['postalCode'])) $this->postalCode = $o['postalCode'];
        if (isset($o['country'])) $this->country = $o['country'];
        if (isset($o['phone'])) $this->phone = $o['phone'];
        if (isset($o['fax'])) $this->fax = $o['fax'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->companyName)) $o['companyName'] = $this->companyName;
        if (isset($this->contactName)) $o['contactName'] = $this->contactName;
        if (isset($this->contactTitle)) $o['contactTitle'] = $this->contactTitle;
        if (isset($this->address)) $o['address'] = $this->address;
        if (isset($this->city)) $o['city'] = $this->city;
        if (isset($this->region)) $o['region'] = $this->region;
        if (isset($this->postalCode)) $o['postalCode'] = $this->postalCode;
        if (isset($this->country)) $o['country'] = $this->country;
        if (isset($this->phone)) $o['phone'] = $this->phone;
        if (isset($this->fax)) $o['fax'] = $this->fax;
        return empty($o) ? new class(){} : $o;
    }
}

// @DataContract
class Order implements JsonSerializable
{
    public function __construct(
        // @DataMember
        /** @var int */
        public int $id=0,

        // @DataMember
        /** @var string */
        public string $customerId='',

        // @DataMember
        /** @var int */
        public int $employeeId=0,

        // @DataMember
        /** @var DateTime|null */
        public ?DateTime $orderDate=null,

        // @DataMember
        /** @var DateTime|null */
        public ?DateTime $requiredDate=null,

        // @DataMember
        /** @var DateTime|null */
        public ?DateTime $shippedDate=null,

        // @DataMember
        /** @var int|null */
        public ?int $shipVia=null,

        // @DataMember
        /** @var float */
        public float $freight=0.0,

        // @DataMember
        /** @var string */
        public string $shipName='',

        // @DataMember
        /** @var string */
        public string $shipAddress='',

        // @DataMember
        /** @var string */
        public string $shipCity='',

        // @DataMember
        /** @var string */
        public string $shipRegion='',

        // @DataMember
        /** @var string */
        public string $shipPostalCode='',

        // @DataMember
        /** @var string */
        public string $shipCountry=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['customerId'])) $this->customerId = $o['customerId'];
        if (isset($o['employeeId'])) $this->employeeId = $o['employeeId'];
        if (isset($o['orderDate'])) $this->orderDate = JsonConverters::from('DateTime', $o['orderDate']);
        if (isset($o['requiredDate'])) $this->requiredDate = JsonConverters::from('DateTime', $o['requiredDate']);
        if (isset($o['shippedDate'])) $this->shippedDate = JsonConverters::from('DateTime', $o['shippedDate']);
        if (isset($o['shipVia'])) $this->shipVia = $o['shipVia'];
        if (isset($o['freight'])) $this->freight = $o['freight'];
        if (isset($o['shipName'])) $this->shipName = $o['shipName'];
        if (isset($o['shipAddress'])) $this->shipAddress = $o['shipAddress'];
        if (isset($o['shipCity'])) $this->shipCity = $o['shipCity'];
        if (isset($o['shipRegion'])) $this->shipRegion = $o['shipRegion'];
        if (isset($o['shipPostalCode'])) $this->shipPostalCode = $o['shipPostalCode'];
        if (isset($o['shipCountry'])) $this->shipCountry = $o['shipCountry'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->customerId)) $o['customerId'] = $this->customerId;
        if (isset($this->employeeId)) $o['employeeId'] = $this->employeeId;
        if (isset($this->orderDate)) $o['orderDate'] = JsonConverters::to('DateTime', $this->orderDate);
        if (isset($this->requiredDate)) $o['requiredDate'] = JsonConverters::to('DateTime', $this->requiredDate);
        if (isset($this->shippedDate)) $o['shippedDate'] = JsonConverters::to('DateTime', $this->shippedDate);
        if (isset($this->shipVia)) $o['shipVia'] = $this->shipVia;
        if (isset($this->freight)) $o['freight'] = $this->freight;
        if (isset($this->shipName)) $o['shipName'] = $this->shipName;
        if (isset($this->shipAddress)) $o['shipAddress'] = $this->shipAddress;
        if (isset($this->shipCity)) $o['shipCity'] = $this->shipCity;
        if (isset($this->shipRegion)) $o['shipRegion'] = $this->shipRegion;
        if (isset($this->shipPostalCode)) $o['shipPostalCode'] = $this->shipPostalCode;
        if (isset($this->shipCountry)) $o['shipCountry'] = $this->shipCountry;
        return empty($o) ? new class(){} : $o;
    }
}

// @DataContract
class OrderDetail implements JsonSerializable
{
    public function __construct(
        // @DataMember
        /** @var int */
        public int $orderId=0,

        // @DataMember
        /** @var int */
        public int $productId=0,

        // @DataMember
        /** @var float */
        public float $unitPrice=0.0,

        // @DataMember
        /** @var int */
        public int $quantity=0,

        // @DataMember
        /** @var float */
        public float $discount=0.0
    ) {
    }

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

// @DataContract
class CustomerOrder implements JsonSerializable
{
    public function __construct(
        // @DataMember
        /** @var Order|null */
        public ?Order $order=null,

        // @DataMember
        /** @var array<OrderDetail>|null */
        public ?array $orderDetails=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['order'])) $this->order = JsonConverters::from('Order', $o['order']);
        if (isset($o['orderDetails'])) $this->orderDetails = JsonConverters::fromArray('OrderDetail', $o['orderDetails']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->order)) $o['order'] = JsonConverters::to('Order', $this->order);
        if (isset($this->orderDetails)) $o['orderDetails'] = JsonConverters::toArray('OrderDetail', $this->orderDetails);
        return empty($o) ? new class(){} : $o;
    }
}

// @DataContract
class CustomerDetailsResponse implements JsonSerializable
{
    public function __construct(
        // @DataMember
        /** @var Customer|null */
        public ?Customer $customer=null,

        // @DataMember
        /** @var array<CustomerOrder>|null */
        public ?array $orders=null,

        // @DataMember
        /** @var ResponseStatus|null */
        public ?ResponseStatus $responseStatus=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['customer'])) $this->customer = JsonConverters::from('Customer', $o['customer']);
        if (isset($o['orders'])) $this->orders = JsonConverters::fromArray('CustomerOrder', $o['orders']);
        if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->customer)) $o['customer'] = JsonConverters::to('Customer', $this->customer);
        if (isset($this->orders)) $o['orders'] = JsonConverters::toArray('CustomerOrder', $this->orders);
        if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
        return empty($o) ? new class(){} : $o;
    }
}

class GetCustomerDetails implements IGet, JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $id=''
    ) {
    }

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

PHP GetCustomerDetails DTOs

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

HTTP + XML

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

POST /customers/{Id} HTTP/1.1 
Host: northwind.netcore.io 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<GetCustomerDetails xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel">
  <Id>String</Id>
</GetCustomerDetails>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<CustomerDetailsResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel">
  <Customer xmlns:d2p1="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel.Types">
    <d2p1:Address>String</d2p1:Address>
    <d2p1:City>String</d2p1:City>
    <d2p1:CompanyName>String</d2p1:CompanyName>
    <d2p1:ContactName>String</d2p1:ContactName>
    <d2p1:ContactTitle>String</d2p1:ContactTitle>
    <d2p1:Country>String</d2p1:Country>
    <d2p1:Fax>String</d2p1:Fax>
    <d2p1:Id>String</d2p1:Id>
    <d2p1:Phone>String</d2p1:Phone>
    <d2p1:PostalCode>String</d2p1:PostalCode>
    <d2p1:Region>String</d2p1:Region>
  </Customer>
  <Orders xmlns:d2p1="http://schemas.datacontract.org/2004/07/Northwind.ServiceModel.Types">
    <d2p1:CustomerOrder>
      <d2p1:Order>
        <d2p1:CustomerId>String</d2p1:CustomerId>
        <d2p1:EmployeeId>0</d2p1:EmployeeId>
        <d2p1:Freight>0</d2p1:Freight>
        <d2p1:Id>0</d2p1:Id>
        <d2p1:OrderDate>0001-01-01T00:00:00</d2p1:OrderDate>
        <d2p1:RequiredDate>0001-01-01T00:00:00</d2p1:RequiredDate>
        <d2p1:ShipAddress>String</d2p1:ShipAddress>
        <d2p1:ShipCity>String</d2p1:ShipCity>
        <d2p1:ShipCountry>String</d2p1:ShipCountry>
        <d2p1:ShipName>String</d2p1:ShipName>
        <d2p1:ShipPostalCode>String</d2p1:ShipPostalCode>
        <d2p1:ShipRegion>String</d2p1:ShipRegion>
        <d2p1:ShipVia>0</d2p1:ShipVia>
        <d2p1:ShippedDate>0001-01-01T00:00:00</d2p1:ShippedDate>
      </d2p1:Order>
      <d2p1:OrderDetails>
        <d2p1:OrderDetail>
          <d2p1:Discount>0</d2p1:Discount>
          <d2p1:OrderId>0</d2p1:OrderId>
          <d2p1:ProductId>0</d2p1:ProductId>
          <d2p1:Quantity>0</d2p1:Quantity>
          <d2p1:UnitPrice>0</d2p1:UnitPrice>
        </d2p1:OrderDetail>
      </d2p1:OrderDetails>
    </d2p1:CustomerOrder>
  </Orders>
  <ResponseStatus xmlns:d2p1="http://schemas.servicestack.net/types">
    <d2p1:ErrorCode>String</d2p1:ErrorCode>
    <d2p1:Message>String</d2p1:Message>
    <d2p1:StackTrace>String</d2p1:StackTrace>
    <d2p1:Errors>
      <d2p1:ResponseError>
        <d2p1:ErrorCode>String</d2p1:ErrorCode>
        <d2p1:FieldName>String</d2p1:FieldName>
        <d2p1:Message>String</d2p1:Message>
        <d2p1:Meta xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
          <d5p1:KeyValueOfstringstring>
            <d5p1:Key>String</d5p1:Key>
            <d5p1:Value>String</d5p1:Value>
          </d5p1:KeyValueOfstringstring>
        </d2p1:Meta>
      </d2p1:ResponseError>
    </d2p1:Errors>
    <d2p1:Meta xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
      <d3p1:KeyValueOfstringstring>
        <d3p1:Key>String</d3p1:Key>
        <d3p1:Value>String</d3p1:Value>
      </d3p1:KeyValueOfstringstring>
    </d2p1:Meta>
  </ResponseStatus>
</CustomerDetailsResponse>