How to extract bitly_gif_url from Giphy API JSON data

I’m working with the Giphy API and having trouble accessing specific values from the JSON response. When I make a request to get GIF data, I receive a response but can’t seem to extract the bitly_gif_url field properly.

Here’s what I’m trying:

$.ajax({
    url: giphyEndpoint,
    method: 'GET',
    success: function(response) {
        $.each(response, function(i) {
            console.log(response[i].bitly_gif_url);
        });
    }
});

The console keeps showing undefined instead of the actual URL. I’ve tried several different approaches to navigate through the response object but nothing seems to work. The API returns data successfully, I just can’t access the nested properties correctly. Any ideas on what I might be doing wrong?

You’re probably not accessing the right part of the Giphy API response. The response wraps everything in a data array - that’s where the actual GIF objects live. Try iterating through response.data instead:

$.ajax({
    url: giphyEndpoint,
    method: 'GET',
    success: function(response) {
        $.each(response.data, function(i, gif) {
            console.log(gif.bitly_gif_url);
        });
    }
});

I hit this same wall when I started using Giphy’s API. The main response wraps the GIF data in a data property, so you’ve got to go one level deeper to grab stuff like bitly_gif_url.