Cookie consent

AstroBin saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing AstroBin without changing the browser settings, you grant us permission to store that information on your device.

I agree

API documentation and examples

rudibr
11 Sep, 2018 07:52
Hi,

I have tried to simply get todays Image Of The Day.

This request (keys are hidden):
https://www.astrobin.com/api/v1/imageoftheday/?limit=1&api_key={HIDDEN}&api_secret={HIDDEN}&format=json
 Gives this response (keys are hidden):
{
   "meta":
   {
      "limit": 1,
      "next": "/api/v1/imageoftheday/?api_secret={HIDDEN}&api_key={HIDDEN}&limit=1&offset=1&format=json",
      "offset": 0,
      "previous": null,
      "total_count": 2043
   },
   "objects": [
      {
         "date": "2018-09-11",
         "image": "/api/v1/image/365051/",
         "resource_uri": "/api/v1/imageoftheday/2232/",
         "runnerup_1": null,
         "runnerup_2": null
      }
   ]
}
But how do I get from that to an URL to the Image Of The Day?

Here: https://www.astrobin.com/help/api/
The documentation says:
>>
If you get an Image object using the APIs, it will have a filename and original_ext field. To display the image, you must append them to https://cdn.astrobin.com/
<<

But no filename nor original_ext field are returned?

What am I doing wrong?
Are there a more comprehensive guide for the API available for dummies like me smile
siovene
11 Sep, 2018 10:28
Sorry, the documentation is wrong (pull request welcome!)

You need to do an additionally API call to fetch the image resource (in your example it's "/api/v1/image/365051/" ) and that will return an object with several URLs in it for multiple sizes.
Edited 11 Sep, 2018 10:29
rudibr
11 Sep, 2018 12:55
Thanks for the quick response, will try that.
alextardif
03 Feb, 2019 18:36
Salvatore Iovene
Sorry, the documentation is wrong (pull request welcome!)You need to do an additionally API call to fetch the image resource (in your example it's "/api/v1/image/365051/" ) and that will return an object with several URLs in it for multiple sizes.

Hi Salvatore - could you expand on that please?  I've gotten to the same exact point as the example above, but struggling to figure out how to get to the actual image url?

Also, curious - do your APIs offer the ability to pull the "Technical Card" data associated with the images?  Such as image metadata or equipment user to capture the image?

Regards,
Alex
siovene
03 Feb, 2019 18:41
Hi Alex,
you request the latest IOTD e.g.

https://www.astrobin.com/api/v1/imageoftheday/?limit=1&api_key={HIDDEN}&api_secret={HIDDEN}&format=json

The response JSON contains

"image": "/api/v1/image/123456/",

so you request that image:

https://www.astrobin.com/api/v1/image/?id=123456&api_key={HIDDEN}&api_secret={HIDDEN}&format=json

The JSON in the response will have several URLs properties for different sizes, it's pretty explanatory.

Technical card data is not available at this time.
alextardif
03 Feb, 2019 19:28
var url = "https://astrobin.com/api/v1/imageoftheday/?limit=1&api_key={HIDDEN}&api_secret={HIDDEN}&format=json";
$.ajax({ url: url, method: "GET" }).then(function(result){ $("#returnObjectAstrobin"smile.text(JSON.stringify(result, null, 4)); // THIS RETURNS: same as original example above.
 // THEN I MAKE THE NEXT CALL BASED ON YOUR INSTRUCTIONS ABOVE: var imageUrl = "https://www.astrobin.com/api/v1/image/?id=388185&api_key={HIDDEN}&api_secret={HIDDEN}&format=json"; $.ajax({ url: imageUrl, method: "GET" }).then(function(test){ console.log("*RETURN ASTROBIN IMAGE OBJECT: "+ test); //       THIS RETURNS: GET ***** 400 ERROR… /// }); });
Sorry, one more time, if I may… I'm struggling getting to those image url's - getting a GET 400 error?  My basic code is above - any thoughts?
siovene
03 Feb, 2019 19:56
Sorry, my bad. Instead of image?id=12345, it’s just image/12345.
alextardif
03 Feb, 2019 22:33
Hm… still no luck using:

"https://astrobin.com/api/v1/image/388185&api_key={HIDDEN}&api_secret={HIDDEN}&format=json"
Are you able to test and share a more complete bock of code of the ajax call?
siovene
03 Feb, 2019 23:30
Alex,
the HTTP parameters list must start with a ?, not with an &.
alextardif
04 Feb, 2019 16:04
Ah, I finally got to the URL and other details - thank you!  I'll tinker with it some more and I'm sure I'll have more questions smile
 
Register or login to create to post a reply.