flickr / flickr-sdk

Almost certainly the best Flickr API client in the world for node and the browser
https://www.flickr.com/services/api
MIT License
131 stars 29 forks source link

Hitting 413 (Request Too Large) error on flickr.photosets.editPhotos #143

Closed wwarby closed 2 years ago

wwarby commented 3 years ago

I'm attempting to update a photoset with several hundred photos in it, and hitting a 413 response (request too large). Here's what I'm doing:

flickr.photosets.editPhotos({
  photoset_id: albumId,
  photo_ids: photoIds.join(','), // Several hundred IDs in this array
  primary_photo_id: primaryPhotoId
})

I can see from the error response that the bit long set of photo IDs is being passed as a query string param, despite the method being POST:

https://api.flickr.com/services/rest?method=flickr.photosets.editPhotos&photoset_id=72157720077649915&photo_ids=51545392449%2C51545579665%2C51544622751%2C51545369594%2C51545330174...

Is there any way to coerce the library to send the parameters of this method as a post body rather than as a query string? I couldn't see anything obvious in the documentation, but it looks as though the Flickr API itself should support this in principle.

wwarby commented 3 years ago

I've tracked down the cause of this issue I think and hacked in a fix that works - at least for my use case.

https://github.com/flickr/flickr-sdk/blob/df3108bc66d134094a242df4b7016379785c644e/script/build-rest.ejs#L96

Replacing this line with .param(args) makes the problem go away. Is this a bug I've stumbled over with an easy fix?

edwarddistel commented 2 years ago

I can confirm @wwarby's bug and super helpful 1-line fix. I was getting a 414 error and unable to reorder photos until I made this change.

Thank you @wwarby!

jeremyruppel commented 2 years ago

Thanks for the bug fix! This should be fixed in v5.0.0.