Create a location

Create a location

POST api/locations

Creates a new location. Locations are auto-generated when new nodes are created. Nodes with the same node number are auto-assigned to the same location.

Request syntax

post api/locations '{"name":"<string>","city":"<string>","state":"<string>","addressline1":"<string>","zipcode":"<string>","country":"<string>","nodes":["<string>","<string>"]}'

Request parameters

The request accepts the following data in JSON format.

ParameterTypeDescriptionRequiredDefault value
nameStringThe name of the location.YesN/A
cityStringThe city where the location is physically located.NoAustin
stateStringThe state where the location is physically located.NoTX
addressline1StringThe first line of the physical address of the location.No123 Please Update Me
addressline2StringThe second line of the physical address of the location.NoN/A
zipcodeStringThe zip code where the location is physically located.No11111
countryStringThe country where the location is physically located.NoUS
nodesStringThe hostnames of the nodes to associate with the location. If the nodes are already assigned to a different location, the nodes will be moved from the previous location to the new location.NoN/A

Response syntax

{
    "location_id": integer,
    "name": "string",
    "template_name": "string",
    "addressline1": "string",
    "addressline2": "string",
    "city": "string",
    "state": "string",
    "zipcode": "string",
    "country": "string",
    "updated_at": "timestamp",
    "nodes": [
        {
            "node_id": integer,
            "hostname": "string",
            "keepalive": "string",
            "keepalive_timestamp": timestamp,
            "last_online": "timestamp",
            "hardware_type": "string",
            "updated_at": "timestamp"
        }
    ]
}

Response parameters

If the action is successful, an HTTP 200 response is returned. The following data is returned in JSON format.

FieldTypeDescription
location_idIntegerThe ID of the location.
nameStringThe name of the location.
template_nameStringThe name of the template used to create the location.
addressline1StringThe first line of the physical address specified in the request. If the value wasn't in the request, the default value is returned.
addressline2StringThe second line of the physical address specified in the request. If the value wasn't in the request, the default value is returned.
cityStringThe city specified in the request. If the value wasn't in the request, the default value is returned.
stateStringThe state specified in the request. If the value wasn't in the request, the default value is returned.
zipcodeStringThe zip code specified in the request. If the value wasn't in the request, the default value is returned.
countryStringThe country specified in the request. If the value wasn't in the request, the default value is returned.
updated_atTimestampThe timestamp indicating when the location was last updated.
nodesArray of ObjectsThe details of the nodes associated with the location.

Errors

The following are errors returned by this API. For a complete list of common errors, see Common errors.

CodeMessageCause
422Validation Failed: addressline1, city, state, zipcode, country provide all or none of parametersThe addressline1, city, state, zipcode, and country fields must either always be present, or omitted in the request.

Examples

Example: Create a new location and associate two nodes

This example creates a new location named Test Location with a physical location and associates nodes sit0000red0 and sit0000red1 with it.

ruby api.rb <customer_code> post /api/locations '{"name":"Test Location","city":"Austin","state":"TX","addressline1":"123 Test Way","zipcode":"11111","country":"US","nodes":["sit0000red0","sit0000red1"]}'

Response

{
    "location_id": 25844,
    "name": "Test Location",
    "template_name": "test-location",
    "addressline1": "123 Test Way",
    "addressline2": null,
    "city": "Austin",
    "state": "TX",
    "zipcode": "11111",
    "country": "US",
    "updated_at": "2024-10-02T15:31:00.243Z",
    "nodes": [
        {
            "node_id": 120081,
            "hostname": "sit0000red0",
            "keepalive": "unknown",
            "keepalive_timestamp": 1727882885,
            "last_online": "unknown",
            "hardware_type": "test hardware",
            "updated_at": "2024-10-02T15:31:00.208Z"
        },
        {
            "node_id": 120082,
            "hostname": "sit0000red1",
            "keepalive": "unknown",
            "keepalive_timestamp": 1727882885,
            "last_online": "unknown",
            "hardware_type": "test hardware",
            "updated_at": "2024-10-02T15:31:00.232Z"
        }
    ]
}