Help Center

Resource: Age Group

Resource: Age Group

Data Elements

Name Read Only Required Type Length Notes
id Yes Number
name Yes String 90
game_length Yes Number In minutes. Default of 60 will be used if not specified.
created_at Yes String RFC-822 Date Format, local time zone
updated_at Yes String RFC-822 Date Format, local time zone

Notes

  • If an age group has related games, it cannot be deleted.

Validations

  • name must be unique.

Retrieve a list of age groups (INDEX)

Return a paginated list of age groups. Limit is 50 age groups per request.

Sample Response: GET /age_groups.xml

<?xml version="1.0" encoding="UTF-8"?>
<age_groups>
  <page>1</page>
  <pages>2</pages>
  <count>68</count>
  <age_group>
    <id>123</id>
    <name>Div 1</name>
    <game_length>60</game_length>
  </age_group>
  <age_group>
    <id>23010</id>
    <name>Div 2</name>
    <game_length>60</game_length>
  </age_group>
  <age_group>
    <id>10863</id>
    <name>Junior Varsity</name>
    <game_length>60</game_length>
  </age_group>
  <age_group>
    <id>10864</id>
    <name>Middle School</name>
    <game_length>60</game_length>
  </age_group>
  <age_group>
    <id>23000</id>
    <name>MS</name>
    <game_length>60</game_length>
  </age_group>
  <!-- repeat for up to 50 age groups -->
</age_groups>

Sample Response: GET /age_groups.json

{
    "page":1,
    "pages":2,
    "count":68,
    "age_groups":
    [
        {
            "id":123,
            "name":"Div 1",
            "game_length":60
        },
        {
            "id":23010,
            "name":"Div 2",
            "game_length":60
        },
        {
            "id":10863,
            "name":"Junior Varsity",
            "game_length":60
        },
        {
            "id":10864,
            "name":"Middle School",
            "game_length":60
        },
        {
            "id":23000,
            "name":"MS",
            "game_length":60
        },
      .. repeat for up to 50 age groups .. 
    ]
}

Retrieve a specific age group (SHOW)

The following commands will retrieve the age group details.

Sample Response: GET /age_groups/123.xml

<?xml version="1.0" encoding="UTF-8"?>
<age_group>
  <id>123</id>
  <name>Div 1</name>
  <game_length>60</game_length>
</age_group>

Sample Response: GET /age_groups/123.json

{
    "age_group":
    {
        "id":123,
        "name":"Div 1",
        "game_length":60
    }
}

Create a Game (CREATE)

To create an age group, use the POST command to /age_groups.xml or /age_groups.json.

The following status codes can be returned:

  • 201 Created: Successfully created an age group. The response body will have an XML or JSON representation of the age group you created.
  • 403 Unprocessable Entity: The age group failed one or more validation checks.

Sample Request Body: POST /age_groups.xml

<?xml version="1.0" encoding="UTF-8"?>
<age_group>
  <id>123</id>
  <name>Div 1</name>
  <game_length>60</game_length>
</age_group>

Sample Request Body: POST /age_groups.json

{
    "age_group":
    {
        "id":123,
        "name":"Div 1",
        "game_length":60
    }
}

Update a Game (UPDATE)

To update an age group, send a PUT command to /age_groups/123.xml or /age_groups/123.json. The request body should be XML, JSON, or a URL encoded string. If you are only updating a specific field, you can just include the fields you wish to change. For example, if you only want to change the name, the request can look like this:

PUT /age_groups/123.xml
<age_group><name>U-19</name></age_group>

PUT /age_groups/123.xml
age_group[name]=U-19

PUT /age_groups/123.json
{"age_group":{"name":"U-19"}}

Upon successful update of the record, the response code returned will be 200 (OK).

Delete a User (DELETE)

To delete an age group, issue a DELETE command to the age group's URL:

DELETE /age_groups/123.json

The server will respond with a status code 200 (OK) if the age group was deleted, otherwise you will see an error response (422 Unprocessable Entity). No response body is rendered.

Validation Errors

If you try to create, update, or delete an age group, and the change that you want to make validates one or more assignr.com validation rules, assignr.com will respond with a 422 Unprocessable Entity error. The response body will contain details about the error, like this:

<?xml version="1.0" encoding="UTF-8"?>
<error>
  <messages>
    <message>Name is already taken.</message>
  </messages>
</error>

If JSON is requested, it will look like this:

{"error":[
    {"message": "Name is already taken."}
  ]
}