The Axomic OpenAsset REST API is doing its best to totally confuse me. I tend to find that if I write and do, then things become clearer.

Stack overflow only has one question about this particular API, and I asked it… and answered it[1. after getting a very helpful reply to an email that I sent to Axomic help]. The idea of this post is to document the steps I’ve gone through to try to solve the problem so that it is easier for someone who knows what they are doing to fill in the gaps in my knowledge!

My goal

I want to be able to go to a specific project, and then ask that project to give me its hero image

That’s the short term goal, I’m sure I’ll want to do more in the future, but here’s my attempts to solve that problem.

This is a simple ruby file that will send GET requests to an OA server[1. You don’t need to be told to put your details in to the top bit do you?].

This is asking for file number 2 from the general array of files. They don’t seem to be in any sort of order that could be used to one’s advantage.

{
    "copyright_holder_id": "0",
    "photographer_id": "2",
    "original_filename": "S051205_Bluestone_004_Browell.tif",
    "download_count": "0",
    "contains_video": "0",
    "md5_now": "",
    "category_id": "1",
    "caption": "Bligh Voller 4",
    "md5_at_upload": "f37958f1c80b67ae64f527b67b528bf9",
    "id": "2",
    "project_id": "360",
    "click_count": "1",
    "rotation_since_upload": "0",
    "alternate_store_id": "0",
    "duration": "0",
    "description": "Bligh Voller 4",
    "created": "20070220133816",
    "uploaded": "20101202061904",
    "filename": "S051205_N1.tif",
    "contains_audio": "0",
    "access_level": "2",
    "user_id": "12",
    "rank": "5"
}

Maybe this is something to come back to.

The most obvious way to get to files related to a project is through the projects: request = "/REST/1/Projects/2"

which gives:

{
 "name": "Monash University Frankston Campus",
 "name_alias_1": "",
 "code_alias_1": "",
 "name_alias_2": "",
 "id": "2",
 "alive": "1",
 "code_alias_2": "",
 "code": "M020707"
}```

but from projects there's nowhere to go!
##### Nested Resources
* Albums
  * Files
  * Groups
  * Users
* Files
  * Fields
  * Keywords
  * Sizes
* Projects
  * ProjectKeywords
  * Fields
* Fields
  * FieldLookupStrings
* Searches
  * Groups
  * Results
  * Users

`Projects` doesn't have any sub-properties that would be useful. For some reason (maybe it's the OA way) our `Projects` have the same content as our `Albums` as far as I can see. so if I ask for:
```request  = "/REST/1/Albums/384/"```

I get:
```json
{
  "private_image_count": "104,0,0,0",
  "public_image_count": "17,0,0,0",
  "company_album": "0",
  "updated": "20121004164442",
  "id": "384",
  "code": "faad6f4a48ad0dd5345c045e459f7d2a",
  "share_with_all_users": "1",
  "can_modify": 0,
  "locked": "0",
  "all_users_can_modify": "0",
  "name": "Robina Hospital Expansion",
  "description": "B0712003",
  "created": "20121004162913",
  "my_album": 0,
  "shared_album": 1,
  "user_id": "30",
  "unapproved_image_count": "0,0,0,0"
}

which is promising. The Nested Resources list above says that Albums have Files. But for request = "/REST/1/Albums/384/Files" I get

{
  "error_message": "Not a valid URL.",
  "http_status_code": "400"
}```

which is a bit confusing(!) and for `request = "/REST/1/Albums/384/files"` (f not F):
```json
{
  "error_message": "Cannot create requested REST module /REST/1/Albums/384/files",
  "http_status_code": "404"
}```

So that seems like a bit of a dead end.

For the sake of completeness:

```ruby
resourses = ["AccessLevel", "Albums", "AlternateStores", "AspectRatios", "Categories", "CopyrightHolders", "CopyrightPolicies", "Fields", "Files", "Groups", "Keywords", "KeywordCategories", "Photographers", "Projects", "ProjectKeywords", "ProjectKeywordCategories", "Searches", "Sizes", "TextRewrites", "Users"]

resourses.each{|r|
    ask_oa(request+r, baseURL, params, username, password)
}

gives the outcome here.