Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Curl Requests Params inside url

I have an API, where all important Parameter like ID, category is in the Request’s URL and not as payload. What would be the smartest and recommended way to solve this?

curl --request GET \
  --url 'https://api.otto.market/v2/products?sku=SOME_STRING_VALUE&productReference=SOME_STRING_VALUE&category=SOME_STRING_VALUE&brand=SOME_STRING_VALUE&page=SOME_INTEGER_VALUE&limit=SOME_INTEGER_VALUE' \
  --header 'Authorization: Bearer REPLACE_BEARER_TOKEN'

What I did till now

def example(content_type: str, cache_control: str, grand_type:str, client_id:str):

    endpoint = website.BASE_URL
    header_content = {
        'Content-Type': (f'{content_type}'),
        'Cache-Control': (f'{cache_control}')
    }
    data_content = {
        'grant_type': (f'{grand_type}'),
        'client_id': (f'{client_id}')
    }
    response = requests.get(url= endpoint, headers=header_content, data=data_content, verify=False)
    return response

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

requests.get has optional parameter params where you might deliver dict, consider following simple example

import requests
parameters = {"client":"123","product":"abc","category":"a"}
r = requests.get("https://www.example.com",params=parameters)
print(r.url)  # https://www.example.com/?client=123&product=abc&category=a

For further discussion read Passing Parameters In URLs

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading