IDigBio API v1 Examples: Difference between revisions

add Elasticsearch uuid examples
(add Elasticsearch uuid examples)
Line 40: Line 40:
</pre>
</pre>


=== Fetch A Single Record from the API ===


=== Three ways to fetch a specific record based on iDigBio UUID. ===


Example URL:
; 1. Use the API


http://api.idigbio.org/v1/records/c93ebbee-64b5-4452-9e80-93bbfb11b815
The most complete version of each record provided to iDigBio is stored in the API.
 
 
 
In this example we use the curl command-line utility to fetch a single record from the API using the record's iDigBio uuid, then pipe the output to a JSON pretty printing program for human readability.
 
 
 
Example API Results:


<pre>
<pre>
$ curl -s http://api.idigbio.org/v1/records/c93ebbee-64b5-4452-9e80-93bbfb11b815 | json_pp
$ curl -s -XGET https://api.idigbio.org/v1/records/0cec43d8-9ad5-478a-bea1-397ab5cc4430 | json_pp
{
{
   "idigbio:uuid" : "c93ebbee-64b5-4452-9e80-93bbfb11b815",
   "idigbio:uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
   "idigbio:etag" : "9c1eb0e2c0b94543f69dad5005f700d77f118ff7",
   "idigbio:etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
   "idigbio:links" : {
   "idigbio:links" : {
      "mediarecord" : [
        "http://api.idigbio.org/v1/mediarecords/db38f86b-99f5-4dc4-b4a6-a045a9c35323"
      ],
       "owner" : [
       "owner" : [
         "872733a2-67a3-4c54-aa76-862735a5f334"
         "872733a2-67a3-4c54-aa76-862735a5f334"
       ],
       ],
       "recordset" : [
       "recordset" : [
         "http://api.idigbio.org/v1/recordsets/6bb853ab-e8ea-43b1-bd83-47318fc4c345"
         "http://api.idigbio.org/v1/recordsets/40250f4d-7aa6-4fcc-ac38-2868fa4846bd"
       ]
       ]
   },
   },
   "idigbio:version" : 10,
   "idigbio:version" : 1,
   "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
   "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
   "idigbio:recordIds" : [
   "idigbio:recordIds" : [
       "6bb853ab-e8ea-43b1-bd83-47318fc4c345\\6CB7D2F5-C76E-43FD-BACD-097EC550BA18"
       "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a"
   ],
   ],
   "idigbio:dateModified" : "2014-04-01T23:17:14.780Z",
   "idigbio:dateModified" : "2014-04-20T23:11:09.437Z",
   "idigbio:data" : {
   "idigbio:data" : {
       "dwc:catalogNumber" : "125191-Mollusca",
       "dwc:catalogNumber" : "ASU0000166",
      "dwc:specificEpithet" : "gibberulus",
      "dwc:class" : "Gastropoda",
      "dwc:occurrenceID" : "6CB7D2F5-C76E-43FD-BACD-097EC550BA18",
      "dwc:infraspecificEpithet" : "gibbosus",
      "dwc:recordedBy" : "Kohr, H. H.",
      "dwc:scientificName" : "Strombus gibberulus",
      "dwc:family" : "Strombidae",
       "dwc:basisOfRecord" : "PreservedSpecimen",
       "dwc:basisOfRecord" : "PreservedSpecimen",
       "dwc:collectionCode" : "Invertebrate Zoology",
      "symbiotaverbatimScientificName" : "Abies",
       "dcterms:modified" : "03/21/2014",
       "dwc:collectionCode" : "Plants",
       "dwc:decimalLongitude" : "144.8",
      "dwc:decimalLongitude" : "-105.859665870667",
       "dwc:country" : "USA",
       "dcterms:references" : "http://swbiodiversity.org/seinet/collections/individual/index.php?occid=784316",
       "dwc:scientificNameAuthorship" : "Röding",
       "dwc:scientificNameAuthorship" : "P. Mill.",
       "dwc:locationID" : "ZZZ-072834",
       "dwc:collectionID" : "urn:uuid:a2e32c87-d320-4a01-bafd-a9182ae2e191",
       "dwc:stateProvince" : "Mariana Islands",
      "dwc:minimumElevationInMeters" : "2316",
       "dwc:genus" : "Strombus",
      "dwc:georeferenceSources" : "georef batch tool 2013-05-10",
       "dwc:decimalLatitude" : "13.5",
       "dwc:georeferenceVerificationStatus" : "reviewed - high confidence",
       "dwc:institutionCode" : "FLMNH",
       "dwc:occurrenceRemarks" : "Tree to 4 m;  occasional in N-facing barranca",
       "dwc:order" : "Mesogastropoda",
       "dwc:otherCatalogNumbers" : "153418",
       "dwc:county" : "Guam Island"
       "dwc:rights" : "http://creativecommons.org/licenses/by-nc-sa/3.0/",
       "dwc:decimalLatitude" : "23.5821004818154",
      "dwc:day" : "14",
      "idigbio:recordId" : "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a",
      "dwc:locality" : "Ca. 1 mi N of Hwy 40 between Villa Union and Cd. Durango, and ca. 5 mi W of Durango state border.",
      "dwc:occurrenceID" : "784316",
      "dwc:year" : "1985",
      "dwc:recordedBy" : "T. F. Daniel; ",
      "dwc:family" : "Pinaceae",
      "dwc:scientificName" : "Abies",
      "dwc:georeferencedBy" : "cjsdavis",
      "dwc:recordNumber" : "4031",
      "dcterms:modified" : "2013-05-10 13:39:12",
      "dwc:country" : "Mexico",
      "dwc:eventDate" : "1985-03-14",
      "dwc:verbatimElevation" : "7600ft",
      "dwc:startDayOfYear" : "73",
      "dwc:habitat" : "Pine-oak forest, in N-facing barranca.",
       "dwc:dynamicProperties" : "Tree to 4 m;  occasional in N-facing barranca",
      "dwc:month" : "3",
      "dwc:stateProvince" : "Sinaloa",
      "dwc:genus" : "Abies",
       "dwc:coordinateUncertaintyInMeters" : "1000",
       "dwc:institutionCode" : "ASU"
   }
   }
}
</pre>
; 2. Use the Elasticsearch URL interface with query parameter
The data provided by the Elasticsearch interface may differ slightly from the raw API record since the Elasticsearch data has been indexed for consumption by the portal.
<pre>
$ curl -s -XGET https://search.idigbio.org/idigbio/records/_search?q=uuid:0cec43d8-9ad5-478a-bea1-397ab5cc4430 | json_pp
{
  "hits" : {
      "hits" : [
        {
            "_source" : {
              "collectioncode" : "plants",
              "datecollected" : "1985-03-14",
              "uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
              "geopoint_geohash_6" : "9shwph",
              "locality" : "ca. 1 mi n of hwy 40 between villa union and cd. durango, and ca. 5 mi w of durango state border.",
              "minelevation" : 231,
              "collectionid" : "urn:uuid:a2e32c87-d320-4a01-bafd-a9182ae2e191",
              "datecollected_rejected" : false,
              "datemodified_rejected" : false,
              "geopoint_geohash_5" : "9shwp",
              "recordset" : "40250f4d-7aa6-4fcc-ac38-2868fa4846bd",
              "geopoint_rejected" : false,
              "hasImage" : true,
              "data" : {
                  "idigbio:uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
                  "idigbio:etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
                  "idigbio:links" : {
                    "mediarecord" : [
                        "http://api.idigbio.org/v1/mediarecords/db38f86b-99f5-4dc4-b4a6-a045a9c35323"
                    ],
                    "owner" : [
                        "872733a2-67a3-4c54-aa76-862735a5f334"
                    ],
                    "recordset" : [
                        "http://api.idigbio.org/v1/recordsets/40250f4d-7aa6-4fcc-ac38-2868fa4846bd"
                    ]
                  },
                  "idigbio:version" : 1,
                  "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
                  "idigbio:recordIds" : [
                    "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a"
                  ],
                  "idigbio:data" : {
                    "dwc:catalogNumber" : "ASU0000166",
                    "dwc:basisOfRecord" : "PreservedSpecimen",
                    "symbiotaverbatimScientificName" : "Abies",
                    "idigbio:links" : {
                        "mediarecord" : [
                          "http://api.idigbio.org/v1/mediarecords/db38f86b-99f5-4dc4-b4a6-a045a9c35323"
                        ],
                        "owner" : [
                          "872733a2-67a3-4c54-aa76-862735a5f334"
                        ],
                        "recordset" : [
                          "http://api.idigbio.org/v1/recordsets/40250f4d-7aa6-4fcc-ac38-2868fa4846bd"
                        ]
                    },
                    "dwc:collectionCode" : "Plants",
                    "dwc:decimalLongitude" : "-105.859665870667",
                    "dcterms:references" : "http://swbiodiversity.org/seinet/collections/individual/index.php?occid=784316",
                    "dwc:scientificNameAuthorship" : "P. Mill.",
                    "dwc:collectionID" : "urn:uuid:a2e32c87-d320-4a01-bafd-a9182ae2e191",
                    "dwc:minimumElevationInMeters" : "2316",
                    "dwc:georeferenceSources" : "georef batch tool 2013-05-10",
                    "dwc:georeferenceVerificationStatus" : "reviewed - high confidence",
                    "dwc:occurrenceRemarks" : "Tree to 4 m;  occasional in N-facing barranca",
                    "dwc:otherCatalogNumbers" : "153418",
                    "dwc:rights" : "http://creativecommons.org/licenses/by-nc-sa/3.0/",
                    "idigbio:version" : 1,
                    "idigbio:recordIds" : [
                        "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a"
                    ],
                    "dwc:decimalLatitude" : "23.5821004818154",
                    "dwc:day" : "14",
                    "idigbio:recordId" : "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a",
                    "dwc:locality" : "Ca. 1 mi N of Hwy 40 between Villa Union and Cd. Durango, and ca. 5 mi W of Durango state border.",
                    "dwc:occurrenceID" : "784316",
                    "idigbio:etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
                    "dwc:year" : "1985",
                    "dwc:recordedBy" : "T. F. Daniel; ",
                    "dwc:recordNumber" : "4031",
                    "dwc:georeferencedBy" : "cjsdavis",
                    "dwc:scientificName" : "Abies",
                    "dwc:family" : "Pinaceae",
                    "dcterms:modified" : "2013-05-10 13:39:12",
                    "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
                    "dwc:country" : "Mexico",
                    "idigbio:dateModified" : "2014-04-20T23:11:09.437Z",
                    "dwc:eventDate" : "1985-03-14",
                    "dwc:verbatimElevation" : "7600ft",
                    "idigbio:uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
                    "dwc:startDayOfYear" : "73",
                    "dwc:habitat" : "Pine-oak forest, in N-facing barranca.",
                    "dwc:dynamicProperties" : "Tree to 4 m;  occasional in N-facing barranca",
                    "dwc:month" : "3",
                    "dwc:stateProvince" : "Sinaloa",
                    "dwc:genus" : "Abies",
                    "dwc:coordinateUncertaintyInMeters" : "1000",
                    "dwc:institutionCode" : "ASU"
                  },
                  "idigbio:dateModified" : "2014-04-20T23:11:09.437Z"
              },
              "scientificname" : "abies",
              "minelevation_rejected" : false,
              "etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
              "maxdepth_rejected" : false,
              "family" : "pinaceae",
              "institutioncode" : "asu",
              "geopoint" : {
                  "lat" : 23.5821004818154,
                  "lon" : -105.859665870667
              },
              "fieldnumber" : "4031",
              "geopoint_geohash_2" : "9s",
              "stateprovince" : "sinaloa",
              "mediarecords" : [
                  "db38f86b-99f5-4dc4-b4a6-a045a9c35323"
              ],
              "country" : "mexico",
              "collector" : "t. f. daniel;",
              "geopoint_geohash_4" : "9shw",
              "version" : 1,
              "genus" : "abies",
              "geopoint_geohash_3" : "9sh",
              "datemodified" : "2014-04-20",
              "catalognumber" : "asu0000166",
              "mindepth_rejected" : false,
              "maxelevation_rejected" : false
            },
            "_score" : 14.695786,
            "_index" : "idigbio-1.0.0",
            "_id" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
            "_type" : "records"
        }
      ],
      "max_score" : 14.695786,
      "total" : 1
  },
  "timed_out" : false,
  "_shards" : {
      "failed" : 0,
      "successful" : 10,
      "total" : 10
  },
  "took" : 4
}
</pre>
; 3. Use the Elasticsearch with json-formatted filter query in the message body
Given a json-formatted query body stored in a file named uuid.json:
<pre>
$ cat uuid.json
{
    "filter" : {
    "term"  :  { "uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430" }
    }
}
</pre>
We get the same results in the data fields:
<pre>
$ curl -s -XGET https://search.idigbio.org/idigbio/records/_search -d@uuid.json | json_pp
{
  "hits" : {
      "hits" : [
        {
            "_source" : {
              "collectioncode" : "plants",
              "datecollected" : "1985-03-14",
              "uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
              "geopoint_geohash_6" : "9shwph",
              "locality" : "ca. 1 mi n of hwy 40 between villa union and cd. durango, and ca. 5 mi w of durango state border.",
              "minelevation" : 231,
              "collectionid" : "urn:uuid:a2e32c87-d320-4a01-bafd-a9182ae2e191",
              "datecollected_rejected" : false,
              "datemodified_rejected" : false,
              "geopoint_geohash_5" : "9shwp",
              "recordset" : "40250f4d-7aa6-4fcc-ac38-2868fa4846bd",
              "geopoint_rejected" : false,
              "hasImage" : true,
              "data" : {
                  "idigbio:uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
                  "idigbio:etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
                  "idigbio:links" : {
                    "mediarecord" : [
                        "http://api.idigbio.org/v1/mediarecords/db38f86b-99f5-4dc4-b4a6-a045a9c35323"
                    ],
                    "owner" : [
                        "872733a2-67a3-4c54-aa76-862735a5f334"
                    ],
                    "recordset" : [
                        "http://api.idigbio.org/v1/recordsets/40250f4d-7aa6-4fcc-ac38-2868fa4846bd"
                    ]
                  },
                  "idigbio:version" : 1,
                  "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
                  "idigbio:recordIds" : [
                    "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a"
                  ],
                  "idigbio:data" : {
                    "dwc:catalogNumber" : "ASU0000166",
                    "dwc:basisOfRecord" : "PreservedSpecimen",
                    "symbiotaverbatimScientificName" : "Abies",
                    "idigbio:links" : {
                        "mediarecord" : [
                          "http://api.idigbio.org/v1/mediarecords/db38f86b-99f5-4dc4-b4a6-a045a9c35323"
                        ],
                        "owner" : [
                          "872733a2-67a3-4c54-aa76-862735a5f334"
                        ],
                        "recordset" : [
                          "http://api.idigbio.org/v1/recordsets/40250f4d-7aa6-4fcc-ac38-2868fa4846bd"
                        ]
                    },
                    "dwc:collectionCode" : "Plants",
                    "dwc:decimalLongitude" : "-105.859665870667",
                    "dcterms:references" : "http://swbiodiversity.org/seinet/collections/individual/index.php?occid=784316",
                    "dwc:scientificNameAuthorship" : "P. Mill.",
                    "dwc:collectionID" : "urn:uuid:a2e32c87-d320-4a01-bafd-a9182ae2e191",
                    "dwc:minimumElevationInMeters" : "2316",
                    "dwc:georeferenceSources" : "georef batch tool 2013-05-10",
                    "dwc:georeferenceVerificationStatus" : "reviewed - high confidence",
                    "dwc:occurrenceRemarks" : "Tree to 4 m;  occasional in N-facing barranca",
                    "dwc:otherCatalogNumbers" : "153418",
                    "dwc:rights" : "http://creativecommons.org/licenses/by-nc-sa/3.0/",
                    "idigbio:version" : 1,
                    "idigbio:recordIds" : [
                        "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a"
                    ],
                    "dwc:decimalLatitude" : "23.5821004818154",
                    "dwc:day" : "14",
                    "idigbio:recordId" : "urn:uuid:5f5e476f-ee39-41c9-8b25-c929f85a773a",
                    "dwc:locality" : "Ca. 1 mi N of Hwy 40 between Villa Union and Cd. Durango, and ca. 5 mi W of Durango state border.",
                    "dwc:occurrenceID" : "784316",
                    "idigbio:etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
                    "dwc:year" : "1985",
                    "dwc:recordedBy" : "T. F. Daniel; ",
                    "dwc:recordNumber" : "4031",
                    "dwc:georeferencedBy" : "cjsdavis",
                    "dwc:scientificName" : "Abies",
                    "dwc:family" : "Pinaceae",
                    "dcterms:modified" : "2013-05-10 13:39:12",
                    "idigbio:createdBy" : "872733a2-67a3-4c54-aa76-862735a5f334",
                    "dwc:country" : "Mexico",
                    "idigbio:dateModified" : "2014-04-20T23:11:09.437Z",
                    "dwc:eventDate" : "1985-03-14",
                    "dwc:verbatimElevation" : "7600ft",
                    "idigbio:uuid" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
                    "dwc:startDayOfYear" : "73",
                    "dwc:habitat" : "Pine-oak forest, in N-facing barranca.",
                    "dwc:dynamicProperties" : "Tree to 4 m;  occasional in N-facing barranca",
                    "dwc:month" : "3",
                    "dwc:stateProvince" : "Sinaloa",
                    "dwc:genus" : "Abies",
                    "dwc:coordinateUncertaintyInMeters" : "1000",
                    "dwc:institutionCode" : "ASU"
                  },
                  "idigbio:dateModified" : "2014-04-20T23:11:09.437Z"
              },
              "scientificname" : "abies",
              "minelevation_rejected" : false,
              "etag" : "2682a8f2fb77d59d50442925a80fe58a2ad51e9c",
              "maxdepth_rejected" : false,
              "family" : "pinaceae",
              "institutioncode" : "asu",
              "geopoint" : {
                  "lat" : 23.5821004818154,
                  "lon" : -105.859665870667
              },
              "fieldnumber" : "4031",
              "geopoint_geohash_2" : "9s",
              "stateprovince" : "sinaloa",
              "mediarecords" : [
                  "db38f86b-99f5-4dc4-b4a6-a045a9c35323"
              ],
              "country" : "mexico",
              "collector" : "t. f. daniel;",
              "geopoint_geohash_4" : "9shw",
              "version" : 1,
              "genus" : "abies",
              "geopoint_geohash_3" : "9sh",
              "datemodified" : "2014-04-20",
              "catalognumber" : "asu0000166",
              "mindepth_rejected" : false,
              "maxelevation_rejected" : false
            },
            "_score" : 1,
            "_index" : "idigbio-1.0.0",
            "_id" : "0cec43d8-9ad5-478a-bea1-397ab5cc4430",
            "_type" : "records"
        }
      ],
      "max_score" : 1,
      "total" : 1
  },
  "timed_out" : false,
  "_shards" : {
      "failed" : 0,
      "successful" : 10,
      "total" : 10
  },
  "took" : 64
}
}
</pre>
</pre>
1,554

edits