'Trouble sending POST request in Python

Can't figure out how to reach the Trip/DuplicateTripWebToLead endpoint from this url

I keep having a 400 error after an evening trying to make it work...

There is a trip parameter where I inserted this 's' variable:

'{"SourceTripId": 33028, "AddQuotation": true, "FromDate": "2022-04-07T00:00:00", "ToDate": null, "TravelersNumber": 100, "AccompagnatorNumber": 50, "Audience": null, "Comment": "TEST TEST", "MailConfirmationRecipients": ["[email protected]"], "Tags": ["TEST", "TEST_AURELIEN"], "ClientTags": ["SegCollège", "EtsPrivé"], "Lead": {"EntityType": 5, "Name": "COLLÈGE ZZZ", "BusinessId": null, "ExternalId": "TEST", "FirstName": "contact", "LastName": "administratif", "Email": "[email protected]", "Phone": null, "Role": "Professeur/enseignant", "Address": "Marseille", "Country": "FRA", "ZIP": "13007", "TripLeaderEmail": "[email protected]", "TripLeaderFullName": "XXX YYY", "TripLeaderFirstName": "XXX", "TripLeaderLastName": "YYY", "TripLeaderPhone": "+33699999999", "TripLeaderAddress": null, "TripLeaderTitleId": null, "TripLeaderCountryISOCode": "FRA", "TripLeaderTags": ["TEST", "TEST_AURELIEN"]}}'

...Into this request

API_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
api_name='Trip'
method_name='DuplicateTripWebToLead'

url = f'https://www.manageyourtrip.com/api/{api_name}/{method_name}'
params = {
            'key': API_KEY,
            'trip': s
         }
r = requests.post(url, params=params)

print(r)

Any help would be appreciated, many thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source