0
def get_prod():
    name = input('Search Query:\n')
    params = {
    'page': '1',
    'perPage': '20',
    'query': name,
}
    response = requests.get('https:///api/public/search', params=params, headers=headers)
    response = response.json()
    id = response['results'][0]['id']
    print(id)
    prod_data = requests.get('https:///api/public/products/{id}', headers=headers)
    print(prod_data.text)

get_prod()

from the public API Search I am returning a valid ID but when the prod_data get request returns the error {"message":"Couldn't find Product with 'id'={id} [WHERE \"products\".\"deleted_at\" IS NULL]"} implying to me that it's not using that variable I can print. When I put a standard finite ID the request works but I'm sure why this won't

1 Answer 1

2

Seems like the variable value is not getting printed. Unless I'm missing something.

You need a f before the string if you're going with this method; f-strings.

prod_data = requests.get(f'https:///api/public/products/{id}', headers=headers)

These might help: https://matthew-brett.github.io/teaching/string_formatting.html

Sign up to request clarification or add additional context in comments.

1 Comment

yep works... such a stupid error on my part smh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.