> ## Content Index
> Fetch the complete content index at: https://scriptcrunch.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Make API Call Using Python
- URL: https://scriptcrunch.com/make-api-call-with-python/
- Published: 2022-08-21T14:56:10.000Z
- Updated: 2026-06-23T08:56:01.000Z
- Author: Scriptcrunch Editorial
- Tags: Python, #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57

In this [guide](https://scriptcrunch.com/tag/guides/) you will learn to make API call using [Python](https://scriptcrunch.com/tag/python/) script using a bearer token and data.

## Make API Call using Python

To make an API call using python, you need to use the [requests module](https://pypi.org/project/requests/?ref=scriptcrunch.com).

First you need to install the requests module using the following command.

```
sudo pip3 install requests
```

Assuming you are making an API request for type `application/x-www-form-urlencoded`, you need to have the following variables set.

1. http endpoint
2. data
3. headers: Mostly Bearer token.

Here is an example.

```
endpoint = "https://endpoint-exampe.com/api"
data = {"scope": "345435"}
headers = {"Authorization": "Bearer dUQsdfErSd34MnV5S1Zhasdf34JHlkjsdklwer&}
```

Finally you need to use the request post method as shown below.

```
requests.post(endpoint, data=data, headers=headers).json()
```

Here is the full script.

```
endpoint = "https://endpoint-exampe.com/api"
data = {"scope": "345435"}
headers = {"Authorization": "Bearer dUQsdfErSd34MnV5S1Zhasdf34JHlkjsdklwer&}
print(requests.post(endpoint, data=data, headers=headers).json())
```

## Possible Errors

While using the requests module, you might get the following error.

```
ModuleNotFoundError: No module named 'requests'
```

You need to install the request module using pip to rectify the `ModuleNotFoundError` error.

You can install the requests module using the following command.

```
sudo pip3 install requests
```