Platform API

<back to all web services

GetStates

Get states for the specified country

The following routes are available for this service:
All Verbs/api/states/{CountryId}
<?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 StateModel implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $StateId='',
        /** @var string|null */
        public ?string $Name=null,
        /** @var string|null */
        public ?string $ShortName=null
    ) {
    }

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

// @ApiResponse(Description="List of states")
class GetStatesResponse implements JsonSerializable
{
    public function __construct(
        /** @var array<StateModel>|null */
        public ?array $States=null,
        /** @var ResponseStatus|null */
        public ?ResponseStatus $ResponseStatus=null
    ) {
    }

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

/** @description Get states for the specified country */
// @Api(Description="Get states for the specified country")
class GetStates implements JsonSerializable
{
    public function __construct(
        /** @description Get states for the specified country id */
        // @ApiMember(Description="Get states for the specified country id", Name="CountryId")
        /** @var string */
        public string $CountryId=''
    ) {
    }

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

PHP GetStates DTOs

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

HTTP + CSV

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

POST /api/states/{CountryId} HTTP/1.1 
Host: pfapi.pstpf.com.au 
Accept: text/csv
Content-Type: text/csv
Content-Length: length

{"CountryId":"00000000-0000-0000-0000-000000000000"}
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length

{"States":[{"StateId":"00000000-0000-0000-0000-000000000000","Name":"String","ShortName":"String"}],"ResponseStatus":{"ErrorCode":"String","Message":"String","StackTrace":"String","Errors":[{"ErrorCode":"String","FieldName":"String","Message":"String","Meta":{"String":"String"}}],"Meta":{"String":"String"}}}