Edit as response because I couldn’t find the edit option.
Adding Documentation to Settings, I replace ‘your_giphy_api_key_here’ with my API key before running it.
*** Settings ***
Documentation A test test for searching GIFs.
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com/v1/gifs/search
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
${NUMBER_OF_GIFS} 5
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${headers}= Create Dictionary api_key=${API_KEY}
${params}= Create Dictionary q=${SEARCH_TERM}
${response}= GET On Session giphy / headers=${headers} params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Log ${json}['data']
After removing ${NUMBER_OF_GIFS} and limit from the request, I get the error
MissingSchema: Invalid URL 'api.giphy.com/v1/gifs/search/': No schema supplied. Perhaps you meant http://api.giphy.com/v1/gifs/search/?
When adding ‘?’ to the end of ${BASE_URL}, I get the following
HTTPError: 401 Client Error: Unauthorized for url: https://api.giphy.com/v1/gifs/search?/&q=cheeseburger
As a first step I’ll suggest you try it like this:
*** Settings ***
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
${NUMBER_OF_GIFS} 5
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${headers}= Create Dictionary api_key=${API_KEY}
${params}= Create Dictionary q=${SEARCH_TERM} limit=${NUMBER_OF_GIFS}
${response}= Get Request giphy /v1/gifs/search headers=${headers} params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Should Contain ${json}['data'] ${NUMBER_OF_GIFS} items
Log ${json}['data']
Note the changes to the ${BASE_URL} and GET On Session lines
Also from the docs It looks like you can just put the api_key in ${params} and you then wouldn’t need the ${headers} at all which might make things simpler
*** Settings ***
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
${NUMBER_OF_GIFS} 5
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${params}= Create Dictionary q=${SEARCH_TERM} limit=${NUMBER_OF_GIFS} api_key=${API_KEY}
${response}= Get Request giphy /v1/gifs/search params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Should Contain ${json}['data'] ${NUMBER_OF_GIFS} items
Log ${json}['data']
You’ll see in the Documentation for Create Session it says
url Base url of the server
Though you might also be able to do this:
*** Settings ***
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com/v1/gifs
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
${NUMBER_OF_GIFS} 5
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${params}= Create Dictionary q=${SEARCH_TERM} limit=${NUMBER_OF_GIFS} api_key=${API_KEY}
${response}= Get Request giphy /search params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Should Contain ${json}['data'] ${NUMBER_OF_GIFS} items
Log ${json}['data']
Thanks to your reply I managed to come with a script that actually works
*** Settings ***
Documentation A test suite for searching GIFs.
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${params}= Create Dictionary q=${SEARCH_TERM} api_key=${API_KEY}
${response}= GET On Session giphy /v1/gifs/search params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Log ${json}['data']
I have one question though, why I am getting error
*** Settings ***
Documentation A test suite for searching GIFs.
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.giphy.com
${API_KEY} your_giphy_api_key_here
${SEARCH_TERM} cheeseburger
*** Test Cases ***
Search for GIFs
[Documentation] Search for GIFs using the GIPHY API
Create Session giphy ${BASE_URL}
${params}= Create Dictionary q=${SEARCH_TERM} api_key=${API_KEY}
${response}= GET On Session giphy /v1/gifs/search params=${params}
Should Be Equal As Strings ${response.status_code} 200
${json}= Set Variable ${response.json()}
Log ${json['data']}