Search code examples
pythonpython-3.xpython-requestspagerduty

convert curl get to rest api to python


I have this curl command:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=y_NbAkKc66ryYTWUXYEu' 'https://api.pagerduty.com/services?time_zone=UTC&sort_by=name'

I need to convert it to python using requests library

import requests

def support(self): 
    services_list = requests.get('I need to convert the link to pass it here as a parameter')

Solution

  • import requests
    
    def support():
        headers = {
            'Accept': 'application/vnd.pagerduty+json;version=2',
            'Authorization': 'Token token=y_NbAkKc66ryYTWUXYEu'}
    
        payloads = (
            ('time_zone', 'UTC'),
            ('sort_by', 'name'),)
    
        services_list = requests.get('https://api.pagerduty.com/services', headers=headers, params=payloads)