POST JSON With Bearer Token Authorization Header [Python Code]

To send a POST JSON request with a Bearer Token authorization header, you need to make an HTTP POST request, provide your Bearer Token with an Authorization: Bearer {token} HTTP header and give the JSON data in the body of the POST message. The Accept: application/json header tells the server that the client expects JSON data in response. For security reasons, bearer tokens are only sent over HTTPS (SSL). Click Send to execute the POST JSON request with a Bearer Token Authorization Header example online and see results. The Python code was automatically generated for the POST JSON Bearer Token Authorization Header example.
POST JSON With Bearer Token Authorization Header [Python Code] Send
POST /echo/post/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Authorization: Bearer {token}
Content-Type: application/json
Content-Length: 61

{
	"employee":{ "name":"Emma", "age":28, "city":"Boston" }
} 
Updated: Viewed: 26525 times
Python code for POST JSON Bearer Token Authorization Header example

Python code for POST JSON Bearer Token Authorization Header Example

This Python code snippet was generated automatically for the POST JSON Bearer Token Authorization Header example.
<< Back to the POST JSON Bearer Token Authorization Header example

What it JSON?

JSON (JavaScript Object Notation) is a lightweight text-based, language-independent data exchange format that specifies formatting rules for the portable representation of structured data. JSON is self-describing, easy to understand, and language independent. JSON is used for client/server communication in web and mobile applications.

What is HTTP POST?

The HTTP POST method is the most commonly used of the nine standard Hypertext Transfer Protocol (HTTP) methods. The POST method requests the webserver to receive and process the data contained in the body of the POST message. The POST request is usually used when submitting an HTML form or when uploading data to a server. Unlike GET and HEAD requests, the HTTP POST requests may change the server state.

What is Bearer Authentication?

HTTP provides a framework for user authentication to control access to protected resources. Bearer authentication (token authentication) is done by sending security tokens in the authorization header. You can do bearer authentication with any programming language. The Bearer Token is a string with no meaning or uses but becomes important within a proper tokenization system. The server usually generates the bearer token in response to a login request and saves it in the browser or local storage. For security reasons, the bearer token should only be sent over HTTPS (SSL) connections.

Bearer Token Authentication Syntax
Authorization: Bearer {token}

How to POST JSON request with Bearer Token Authentication?

An example of sending a POST JSON request with a Bearer Token authentication header that we send to the echo ReqBin URL:

POST JSON With Bearer Token Authentication Example
POST /echo/post/json HTTP/1.1
Authorization: Bearer {token}
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 61
      
{
  "employee":{ "name":"Emma", "age":28, "city":"Boston" }
}

See also

Generate code snippets for Python and other programming languages

Convert your POST JSON Bearer Token Authorization Header request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the Python code generator.