Using Python to make API calls

akugel | Oct. 11, 2022, 10:52 a.m.

Hello Django nation. I recently had to audit a list of over 600 records. I was given a unique id, a module within our CRM platform, and I needed to make an api call to retrieve information. I decided the best way to this was by using python, with the help of the re and requests modules.

The first order of business was to deal with authentication. I registered my own application within the developer console within our CRM application. I was then able to use a refresh token to generate an oauth bearer token. I then created a python dictionary with key being ‘Authorization’ and the value containing my oauth token.

I then created a for loop which went through each line in my file, and using regex, grabbed both the record and module. I then passed this to a formatted string containing the url of the api endpoint I was calling. I think took the response, formatted it as a dictionary using the requests module’s .json() method. From there I was able to grab the necessary fields and write them to a txt file.

This is where python truly shines. Whipping up a simple script like this doesn’t take much time at all.

1 comments

Carlotta Oct. 25, 2022, 4:42 p.m.

I liked the Soccer Mommy clip!

Leave a comment

About Me

I'm Anthony Kugel, a cloud engineer and freelance web developer. I made this site with the help of djangocentral.com.

LinkedIn
What I'm listening To