Foundry API

<back to all web services

CreateMachineRequest

Requires Authentication
The following routes are available for this service:
POST/machines
import Foundation
import ServiceStack

public class CreateMachineRequest : PostOperationTenanted<CreateMachineResponse>
{
    public var name:String?
    public var type:String?
    public var manufacturedOn:Date?
    public var location:String?
    public var timezone:String?

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

    private enum CodingKeys : String, CodingKey {
        case name
        case type
        case manufacturedOn
        case location
        case timezone
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        name = try container.decodeIfPresent(String.self, forKey: .name)
        type = try container.decodeIfPresent(String.self, forKey: .type)
        manufacturedOn = try container.decodeIfPresent(Date.self, forKey: .manufacturedOn)
        location = try container.decodeIfPresent(String.self, forKey: .location)
        timezone = try container.decodeIfPresent(String.self, forKey: .timezone)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if name != nil { try container.encode(name, forKey: .name) }
        if type != nil { try container.encode(type, forKey: .type) }
        if manufacturedOn != nil { try container.encode(manufacturedOn, forKey: .manufacturedOn) }
        if location != nil { try container.encode(location, forKey: .location) }
        if timezone != nil { try container.encode(timezone, forKey: .timezone) }
    }
}

public class PostOperationTenanted<TResponse : Codable> : PostOperationUnTenanted<TResponse>, ITenantedRequest
{
    public var organisationId:String?

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

    private enum CodingKeys : String, CodingKey {
        case organisationId
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        organisationId = try container.decodeIfPresent(String.self, forKey: .organisationId)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if organisationId != nil { try container.encode(organisationId, forKey: .organisationId) }
    }
}

public class PostOperationUnTenanted<TResponse : Codable> : IPost, Codable
{
    required public init(){}
}

public class CreateMachineResponse : Codable
{
    public var responseStatus:ResponseStatus?
    public var machine:Machine?
    public var apiKey:String?

    required public init(){}
}

public class Machine : IIdentifiableResource, Codable
{
    public var name:String?
    public var type:String?
    public var manufacturedOn:Date?
    public var location:String?
    public var configuration:String?
    public var id:String?

    required public init(){}
}


Swift CreateMachineRequest 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 /machines HTTP/1.1 
Host: foundrystage-api-app.azurewebsites.net 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	name: String,
	type: String,
	manufacturedOn: 0001-01-01,
	location: String,
	timezone: String,
	organisationId: String
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	responseStatus: 
	{
		errorCode: String,
		message: String,
		stackTrace: String,
		errors: 
		[
			{
				errorCode: String,
				fieldName: String,
				message: String,
				meta: 
				{
					String: String
				}
			}
		],
		meta: 
		{
			String: String
		}
	},
	machine: 
	{
		name: String,
		type: String,
		manufacturedOn: 0001-01-01,
		location: String,
		configuration: String,
		id: String
	},
	apiKey: String
}