PHPackages                             pedroquezado/correios - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. pedroquezado/correios

ActiveLibrary[HTTP &amp; Networking](/categories/http)

pedroquezado/correios
=====================

Biblioteca para integração com os Correios

v1.1.5(1y ago)216MITPHPPHP ^7.4 || ^8.0

Since Jul 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pedroquezado/correios)[ Packagist](https://packagist.org/packages/pedroquezado/correios)[ RSS](/packages/pedroquezado-correios/feed)WikiDiscussions main Synced today

READMEChangelog (6)DependenciesVersions (8)Used By (0)

Correios API Client - PedroQuezado
==================================

[](#correios-api-client---pedroquezado)

[![Maintainer](https://camo.githubusercontent.com/0a080976a7491620e4b9edfc914dd655ac5dd452570d344c0980aff4e8f99428/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d40706564726f7175657a61646f2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/pedroquezado)[![Source Code](https://camo.githubusercontent.com/9789a1ac2edd21d959175118e813c1103115cd5020efb1a529fbd09f38caf22c/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d706564726f7175657a61646f2f636f727265696f732d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/pedroquezado/correios)[![PHP from Packagist](https://camo.githubusercontent.com/41d4493257297f73d5ee3d1176ba0e55123353b4426d140668a5809489f95fac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706564726f7175657a61646f2f636f727265696f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pedroquezado/correios)[![Latest Version](https://camo.githubusercontent.com/96c2c57f56013f9683c8b7c6f64a477e0eb5f562694017b93b77a3d7a31a1d46/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f706564726f7175657a61646f2f636f727265696f732e7376673f7374796c653d666c61742d737175617265)](https://github.com/pedroquezado/correios/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build](https://camo.githubusercontent.com/c4d33c519cdd36a0c2626663392a32cb2aaf33ebe769fdbc2fc5b9da736e1f84/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f706564726f7175657a61646f2f636f727265696f732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/pedroquezado/correios)[![Quality Score](https://camo.githubusercontent.com/10bd8104d3336a2b496803b684511f2bb6323ccb04415f731ba854df31c30e93/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706564726f7175657a61646f2f636f727265696f732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/pedroquezado/correios)[![Total Downloads](https://camo.githubusercontent.com/35fd67dbac2ba09345c85b2b4e71edd072a93b22ba1701fae5bb71923bcf4510/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706564726f7175657a61646f2f636f727265696f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pedroquezado/correios)

Introduction
------------

[](#introduction)

This package provides an easy-to-use PHP client for interacting with the Correios API. It allows you to fetch pricing and delivery times for different products offered by Correios.

Installation
------------

[](#installation)

First, you need to add the package to your project using Composer.

```
composer require pedroquezado/correios
```

Usage
-----

[](#usage)

### Initialize the Client

[](#initialize-the-client)

To initialize the `Cliente` class, you need to provide your Correios API credentials (username and password), the card number, and an optional fourth parameter to specify the environment (production or homologation). By default, the client uses the production environment.

#### Example

[](#example)

```
require 'vendor/autoload.php';

use PedroQuezado\Code\Correios\Cliente;

// Initialize for production (default)
$cliente = new Cliente('correios_usuario', 'correios_senha_key', 'numero_cartao_postagem');

// Initialize for homologation
$clienteHomologacao = new Cliente('correios_usuario', 'correios_senha_key', 'numero_cartao_postagem', false);
```

- **correios\_usuario**: Your Correios API username.
- **correios\_senha\_key**: Your Correios API password.
- **numero\_cartao\_postagem**: Your Correios card number.
- **producao (optional)**: Boolean flag to specify the environment. Use `true` for production (default) and `false` for homologation.

### Adding Products

[](#adding-products)

The `inserirProduto` method allows you to add products to the client for further operations, such as price and delivery time calculations. The method accepts two parameters: `$coProduto` and an array `$arrProduto` containing the product details.

#### Parameters

[](#parameters)

- **$coProduto**: This is the product code (e.g., '03220' for SEDEX or '03298' for PAC). It is crucial for identifying the product type in subsequent operations.
- **$arrProduto**: An associative array containing the product details, including:
    - **nuRequisicao**: Request number.
    - **cepOrigem**: Origin postal code.
    - **cepDestino**: Destination postal code.
    - **psObjeto**: Object weight in grams.
    - **tpObjeto**: Object type (e.g., '1' for Box/Package).
    - **comprimento**: Object length in centimeters.
    - **largura**: Object width in centimeters.
    - **altura**: Object height in centimeters.
    - **servicosAdicionais**: Array of additional services (e.g., \["001", "019"\]).
    - **vlDeclarado**: Declared value.
    - **dtEvento**: Event date (DD/MM/YYYY).

#### Example

[](#example-1)

```
$cliente->inserirProduto('03220', [
    "nuRequisicao" => "1",
    "cepOrigem" => "70002900",
    "cepDestino" => "05311900",
    "psObjeto" => "8000",
    "tpObjeto" => "1", // Caixa/Pacote
    "comprimento" => "20",
    "largura" => "20",
    "altura" => "20",
    "servicosAdicionais" => ["001", "019"], // Valor Declarado adicionado
    "vlDeclarado" => "100",
    "dtEvento" => "18/03/2022"
]);

$cliente->inserirProduto('03298', [
    "nuRequisicao" => "2",
    "cepOrigem" => "70002900",
    "cepDestino" => "05311900",
    "psObjeto" => "5000",
    "tpObjeto" => "1", // Caixa/Pacote
    "comprimento" => "30",
    "largura" => "30",
    "altura" => "30",
    "servicosAdicionais" => ["001", "064"], // Valor Declarado adicionado
    "vlDeclarado" => "200",
    "dtEvento" => "18/03/2022"
]);
```

#### Importance in Other Methods

[](#importance-in-other-methods)

The `$coProduto` parameter is essential for the `consultarPrecoTotal` and `consultarPrazoTotal` methods. These methods use `$coProduto` to filter and calculate the total price or delivery time for the specified product type. By organizing products with `$coProduto`, you can easily manage and retrieve detailed information for specific product types.

### Fetching Prices

[](#fetching-prices)

You can fetch the prices for the added products using the `consultarPreco` method.

```
try {
    $precos = $cliente->consultarPreco();
    print_r($precos);
} catch (ClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
}
```

### Fetching Delivery Time

[](#fetching-delivery-time)

The `consultarPrazo` method allows you to calculate the delivery time for your products. It takes four parameters:

1. **$dataPostagem**: The posting date in the format YYYY-MM-DD.
2. **$cepOrigem**: The origin postal code.
3. **$cepDestino**: The destination postal code.
4. **$dtEvento**: (Optional) The event date in the format DD-MM-YYYY. If not provided, it defaults to the posting date converted to the required format.

#### Example

[](#example-2)

```
try {
    $prazo = $cliente->consultarPrazo("2024-07-25", "70002900", "05311900");
    print_r($prazo);
} catch (ClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
}
```

#### Parameters Explanation

[](#parameters-explanation)

- **$dataPostagem**: The date when the package is sent. It is essential for calculating the estimated delivery time.
- **$cepOrigem**: The postal code from where the package is sent.
- **$cepDestino**: The postal code to where the package is being delivered.
- **$dtEvento**: This parameter is optional. If not provided, the method will automatically set it to the value of `$dataPostagem` formatted as DD-MM-YYYY. It represents the date of the event related to the delivery.

By calling `consultarPrazo`, you can obtain the estimated delivery time and other related information for each product you have added. The method returns detailed delivery time information, which can be used to inform customers about their expected delivery dates.

### Fetching Total Price

[](#fetching-total-price)

You can fetch the total price for a specific product code using the `consultarPrecoTotal` method.

```
try {
    $precoTotal03220 = $cliente->consultarPrecoTotal('03220');
    echo 'Preço total para o produto 03220: ' . $precoTotal03220 . PHP_EOL;

    $precoTotal03298 = $cliente->consultarPrecoTotal('03298');
    echo 'Preço total para o produto 03298: ' . $precoTotal03298 . PHP_EOL;
} catch (ClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
}
```

### Fetching Total Delivery Time

[](#fetching-total-delivery-time)

You can fetch the total delivery time for a specific product code using the `consultarPrazoTotal` method.

```
try {
    $prazoTotal03220 = $cliente->consultarPrazoTotal('03220');
    echo 'Prazo total para o produto 03220: ' . $prazoTotal03220['prazoEntrega'] . PHP_EOL;

    $prazoTotal03298 = $cliente->consultarPrazoTotal('03298');
    echo 'Prazo total para o produto 03298: ' . $prazoTotal03298['prazoEntrega'] . PHP_EOL;
} catch (ClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
}
```

Exception Handling
------------------

[](#exception-handling)

All exceptions are handled using the `ClienteException` class. This class provides additional information such as the HTTP code and the response from the API.

```
try {
    $precos = $cliente->consultarPreco();
    print_r($precos);

    $prazo = $cliente->consultarPrazo("2024-07-25", "70002900", "05311900");
    print_r($prazo);

    $precoTotal03220 = $cliente->consultarPrecoTotal('03220');
    echo 'Preço total para o produto 03220: ' . $precoTotal03220 . PHP_EOL;

    $precoTotal03298 = $cliente->consultarPrecoTotal('03298');
    echo 'Preço total para o produto 03298: ' . $precoTotal03298 . PHP_EOL;

    $prazoTotal03220 = $cliente->consultarPrazoTotal('03220');
    echo 'Prazo total para o produto 03220: ' . $prazoTotal03220['prazoEntrega'] . PHP_EOL;

    $prazoTotal03298 = $cliente->consultarPrazoTotal('03298');
    echo 'Prazo total para o produto 03298: ' . $prazoTotal03298['prazoEntrega'] . PHP_EOL;
} catch (ClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
    echo 'HTTP Code: ' . $e->getHttpCode();
    echo 'Response: ' . $e->getResponse();
}
```

Documentation
-------------

[](#documentation)

For more detailed information, please refer to the official Correios API documentation:

- [Correios API Documentation](https://cws.correios.com.br/dashboard) (requires login)
- [Manual para Integração Correios API (PDF)](https://www.correios.com.br/atendimento/developers/arquivos/manual-para-integracao-correios-api)

Conclusion
----------

[](#conclusion)

This package simplifies the process of interacting with the Correios API by providing a structured and easy-to-use client. It supports fetching prices and delivery times for various products, handling authentication, and providing detailed error handling.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~47 days

Total

7

Last Release

518d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8839458?v=4)[Pedro Quezado](/maintainers/pedroquezado)[@pedroquezado](https://github.com/pedroquezado)

---

Top Contributors

[![pedroquezado](https://avatars.githubusercontent.com/u/8839458?v=4)](https://github.com/pedroquezado "pedroquezado (4 commits)")

### Embed Badge

![Health badge](/badges/pedroquezado-correios/health.svg)

```
[![Health](https://phpackages.com/badges/pedroquezado-correios/health.svg)](https://phpackages.com/packages/pedroquezado-correios)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.8k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M90](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
