API – basics of connecting + simple queries

Link to Polish version. 

Topic: API – basics of connecting + simple queries

API (Application Programming Interface): an application programming interface provided by many web services. API provides a set of procedures, protocols, and tools enabling sending and receiving content from a given service. Using an appropriate programming language, API allows sending access requests to services from one application to another. The 3 key types of API are: REST API, SOAP API, and RPC API.

REST API: (Representational State Transfer API) is primarily a part of web services designed for making requests and receiving feedback using HTTP functions. There are 4 main HTTP commands on which REST API is based, namely – GET, PUT, POST, DELETE.

SOAP API: (Simple Object Access Protocol), a protocol that adheres to specific standards. It depends on particular systems and programming based on XML. It is also worth mentioning that it requires more information to function properly than other types of this technology. SOAP API is most often used in application programming interfaces dedicated to financial institutions.

RPC API: (Remote Procedure Call) in short, is responsible for remote procedure calling. It was the earliest form of API designed to execute a block of code on another server. It is also worth mentioning that RPC used over HTTP can transform into WEB API.

Below is an example of using SOAP API with the Python language.

Required tools:

requests – One of the most popular Python libraries used for communication with APIs. To use the library, it must be imported in the code:

Next, you need to define the SOAP URL provided in the API documentation:

You need to define the headers as a dictionary and assign them to the variable headers.

The SOAP header is used to include application-specific contextual information in the SOAP request.

The next and most important step is defining the XML request body. The request body template is available at the SOAP URL. You need to specify the required parameters and enter the necessary data. The request body is assigned to the variable payload:

Calling the POST method and assigning the API response to the variable response:

Leave a comment