Field Squared API Services

<back to all web services

InventoryCategory

The following routes are available for this service:
GET,PUT,POST/{Workspace}/InventoryCategory
GET,PUT,POST/{Workspace}/InventoryCategory/{ObjectId}
import Foundation
import ServiceStack

public class InventoryCategory : InventoryTreeNode
{
    public var type:String
    public var objectId:String
    public var workspace:String
    public var itemCategory:String
    public var hideFor:[String] = []
    public var showFor:[String] = []
    public var parentCategoryId:String
    public var enabled:Bool?
    public var childNodes:[InventoryTreeNode] = []
    public var includeInactive:Bool

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case type
        case objectId
        case workspace
        case itemCategory
        case hideFor
        case showFor
        case parentCategoryId
        case enabled
        case childNodes
        case includeInactive
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        type = try container.decodeIfPresent(String.self, forKey: .type)
        objectId = try container.decodeIfPresent(String.self, forKey: .objectId)
        workspace = try container.decodeIfPresent(String.self, forKey: .workspace)
        itemCategory = try container.decodeIfPresent(String.self, forKey: .itemCategory)
        hideFor = try container.decodeIfPresent([String].self, forKey: .hideFor) ?? []
        showFor = try container.decodeIfPresent([String].self, forKey: .showFor) ?? []
        parentCategoryId = try container.decodeIfPresent(String.self, forKey: .parentCategoryId)
        enabled = try container.decodeIfPresent(Bool.self, forKey: .enabled)
        childNodes = try container.decodeIfPresent([InventoryTreeNode].self, forKey: .childNodes) ?? []
        includeInactive = try container.decodeIfPresent(Bool.self, forKey: .includeInactive)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if type != nil { try container.encode(type, forKey: .type) }
        if objectId != nil { try container.encode(objectId, forKey: .objectId) }
        if workspace != nil { try container.encode(workspace, forKey: .workspace) }
        if itemCategory != nil { try container.encode(itemCategory, forKey: .itemCategory) }
        if hideFor.count > 0 { try container.encode(hideFor, forKey: .hideFor) }
        if showFor.count > 0 { try container.encode(showFor, forKey: .showFor) }
        if parentCategoryId != nil { try container.encode(parentCategoryId, forKey: .parentCategoryId) }
        if enabled != nil { try container.encode(enabled, forKey: .enabled) }
        if childNodes.count > 0 { try container.encode(childNodes, forKey: .childNodes) }
        if includeInactive != nil { try container.encode(includeInactive, forKey: .includeInactive) }
    }
}

public class InventoryTreeNode : Codable
{
    public var type:String
    public var descendantCount:Int

    required public init(){}
}


Swift InventoryCategory 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 /{Workspace}/InventoryCategory HTTP/1.1 
Host: dev.fieldsquared.com 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<InventoryCategory xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Field2Office.API.Model.Inventory">
  <DescendantCount>0</DescendantCount>
  <ChildNodes>
    <InventoryTreeNode i:nil="true" />
  </ChildNodes>
  <Enabled>false</Enabled>
  <HideFor xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <d2p1:string>String</d2p1:string>
  </HideFor>
  <IncludeInactive>false</IncludeInactive>
  <ItemCategory>String</ItemCategory>
  <ObjectId>String</ObjectId>
  <ParentCategoryId>String</ParentCategoryId>
  <ShowFor xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <d2p1:string>String</d2p1:string>
  </ShowFor>
  <Workspace>String</Workspace>
</InventoryCategory>