1

I'm following triggering guidelines in Unsplash documentation. So the endpoint is:

GET /photos/:id/download

This is the photo's example response:

{
  "id": "LBI7cgq3pbM",
  "width": 5245,
  "height": 3497,
  "color": "#60544D",
  "urls": { ... },
  "user": { ... },
  "links": {
    "self": "https://api.unsplash.com/photos/LBI7cgq3pbM",
    "html": "https://unsplash.com/photos/LBI7cgq3pbM",
    "download": "https://unsplash.com/photos/LBI7cgq3pbM/download", // don't use this property
    "download_location": "https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM" // use this one ;)
  }
}

"Be sure to include any query parameters included in the URL (like the ixid)."

So my question is what is value od ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM and how to get it?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Nemus
  • 3,879
  • 12
  • 38
  • 57
  • You need to parse the `links.download_location` as a URL. [Here is a good answer](https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript) on Stack Overflow for parsing URL parameters. – Labu May 25 '21 at 14:28

1 Answers1

0

Try the following

const ixid = new URLSearchParams(
  new URL("https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM").search
).get("ixid");
console.log(ixid);
raphael-pa
  • 49
  • 5