Document passing `body` via `client.request()` (using `query` and `headers['Content-Type']`)
Hi there, thanks for this library!
I'm just trying to pass a "Body" option active: true to a new thumbnail, which is mentioned in the API documentation for POST https://api.vimeo.com/videos/{video_id}/pictures (see below)
The numbered comments in the code block below show all of the *non-working* things I've tried (I tried them one by one, on their own):
import { Vimeo } from '@vimeo/vimeo';
const client = new Vimeo(VIMEO_CLIENT_ID, VIMEO_CLIENT_SECRET, VIMEO_ACCESS_TOKEN);
client.request(
{
method: 'POST',
// 1. Pass via query
path: `/videos/${vimeoVideoId}/pictures?active=true`,
// 2. Pass via `body` string
body: JSON.stringify({ active: true }),
// 3. Pass via `body` object
body: { active: true },
// 4. Pass via `query`
query: { active: true },
// 5. Pass via `params`
params: { active: true },
},
(error, response) => {
if (error) {
console.log('error', error);
}
console.log('response', response);
},
);
I don't see the body documented anywhere... is there a way to do this with the client?
The closest thing I can see is this in the tests:
https://github.com/vimeo/vimeo.js/blob/cb62cb6dad0cd12bbbed6fbd0c215471b73f55b2/test/lib/vimeo_test.js#L481-L486
But using headers['Content-Type'] of 'application/json' with a query object also does not set the new thumbnail to active: true 😬
import { Vimeo } from '@vimeo/vimeo';
const client = new Vimeo(VIMEO_CLIENT_ID, VIMEO_CLIENT_SECRET, VIMEO_ACCESS_TOKEN);
client.request(
{
method: 'POST',
path: `/videos/${vimeoVideoId}/pictures`,
headers: { 'Content-Type': 'application/json' },
query: { active: true },
},
(error, response) => {
if (error) {
console.log('error', error);
}
console.log('response', response);
},
);
Ohh, it seems that it's an unusual behavior of the Vimeo API:
⚠️⚠️ If you don't specify time along with active in the body, then active is silently ignored 🤔
Solution code incoming (I will also link to the few other posts which are asking how to create thumbnails)
Add a new thumbnail at 0 seconds of a video
If you uploaded a new video, and want to set a new thumbnail at 0 seconds of the video:
import { Vimeo } from '@vimeo/vimeo';
const client = new Vimeo(VIMEO_CLIENT_ID, VIMEO_CLIENT_SECRET, VIMEO_ACCESS_TOKEN);
client.request(
{
method: 'POST',
path: `/videos/${vimeoVideoId}/pictures`,
headers: { 'Content-Type': 'application/json' },
query: {
active: true, // Make this the active thumbnail
time: 0, // Time offset in seconds from start of video
},
},
(error, response) => {
if (error) {
console.log('error', error);
}
console.log('response', response);
},
);
I renamed this issue to be about documentation, because this approach of passing the body via the query property and needing to also set headers['Content-Type'] to 'application/json' was pretty hidden.
This basic use case should probably be documented front and center on the documentation for this library.
So many hours lost trying to figure this out, thank you, it's a shame that you brought this up over a year ago and it's still not updated on the documentation