2
1
0

Let's say for argument's sake, I hit this endpoint 'https://test1-api.rescuegroups.org/v5/public/animals/search/available/dogs/?limit=100&page=1'


I get the results and under relationships i'm interested in grabbing the image urls from these id numbers:


"pictures": {
                    "data": [
                        {
                            "type": "pictures",
                            "id": "8532912"
                        },
                        {
                            "type": "pictures",
                            "id": "8532913"
                        },
                        {
                            "type": "pictures",
                            "id": "7706350"
                        },
                        {
                            "type": "pictures",
                            "id": "7706351"
                        }
                    ]
                }

What endpoint do I need to hit to achieve this? I've tried all sorts of combinations like https://test1-api.rescuegroups.org/v5/public/animals/pictures/8532912. It doesn't work and the docs don't talk about pictures endpoints at all, only the schema. 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi, Christy,

      I believe your endpoint should already have the data you need, but it requires a bit of work to extract the data in order to use it.

      I ended up matching the picture IDs found in the relationships object with the pictures IDs found in the included object, which is at the same level as the data object and holds the URLs for the pictures. Also, If you don't need everything that the included object holds add include=pictures as a parameter at the end of your endpoint to get something like the code below.

      https://test1-api.rescuegroups.org/v5/public/animals/search/available/dogs/?limit=100&page=1&include=pictures

      "meta":[] // intentionally left empty
      "data: [
      		// other data
      
      		"relationships": {
                      "pictures": {
                          "data": [
                              {
                                  "type": "pictures",
                                  "id": "55066987"  
                              }
                          ]
                      }
                  }
      	]
      "included": [
              {
                  "type": "pictures",
                  "id": "55066987",                  
                  "attributes": {
                      "original": {
                          "filesize": 52363,
                          "resolutionX": 533,
                          "resolutionY": 960,
                          "url": "https://s3.amazonaws.com/filestore.rescuegroups.org/619/pictures/animals/68/68766/55066987_533x960.jpg"
                      },
                      "large": {
                          "filesize": 49497,
                          "resolutionX": 500,
                          "resolutionY": 900,
                          "url": "https://s3.amazonaws.com/filestore.rescuegroups.org/619/pictures/animals/68/68766/55066987_500x900.jpg"
                      },
                      "small": {
                          "filesize": 4931,
                          "resolutionX": 100,
                          "resolutionY": 180,
                          "url": "https://s3.amazonaws.com/filestore.rescuegroups.org/619/pictures/animals/68/68766/55066987_100x180.jpg"
                      },
                      "order": 1,
                      "created": "2018-02-27T20:26:21Z",
                      "updated": "2018-02-27T20:26:22Z"
                  }
              }
          ]

      I hope this helps!

        CommentAdd your comment...