Skip to content

Integration with Correios Sigep Web API

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

marceloperini/sigep_web

Sigep Web

Build Status Gem Version Coverage Status Donate

About

This gem provide a easy way to integrate an application to Correios Sigep Web API, all features is based on this API documentation

Getting started

You can add it to your Gemfile with:

gem 'sigep_web'

or in your console:

gem install sigep_web

Configuration

If you are using Rails put this in your environments configuration files:

SigepWeb.configure do |config|
  config.user = 'YOUR_USER'
  config.password = 'YOUR_PASSWORD'
  config.administrative_code = 'YOUR_ADM_CODE'
  config.card = 'YOUR_CARD_NUMBER'
  config.contract = 'YOUR_CONTRACT_NUMBER'
end

How It Works

Consulting service availability

This check whether a particular service is available from source zip code to target zip code.

SigepWeb.service_availability(service_number: '40215',
                              source_zip: '70002900',
                              target_zip: '74730490')

This method will return a hash like this if has a success response, the second attribute indicate if a particular service is available.

{ success: true, response: true }

Search Client

This method return the available services of specific post card

SigepWeb.search_client(id_contract: "0000000000",
                       id_post_card: "0000000000")

The method will return something like this

{
  success: true,
  response: {
    cnpj: '0000000000',
    contratos: {
      cartoes_postage: {
        codigo_administrativo: '000000000',
        numero: '000000000',
        servicos: [
          {
            codigo: '40096',
            descricao: 'SEDEX - CONTRATO',
            id: '104625'
          },
          ...
        ]
      }
    }
  }
}

Zip Query

This method return the address based on zip code

SigepWeb.zip_query(zip: "70002900")

This method will return a hash like this

{
  success: true,
  response: {
    bairro: 'Asa Norte',
    cep: '70002900',
    cidade: 'Brasília',
    complemento: nil,
    complemento2: nil,
    end: 'SBN Quadra 1 Bloco A',
    id: '0',
    uf: 'DF'
  }
}

Request Labels For Posts

Return one label or a range of labels to use for posts

SigepWeb.request_labels(receiver_type: 'C', identifier: '00000000000000',
                        id_service: '104625', qt_labels: 1)

return:

{ success: true, response: ['DL61145929 BR'] }

Request verifying digit

to generate the verifying digit for a specific label use:

SigepWeb.generate_labels_digit_verifier(labels: 'DL61145929 BR')

return:

{ success: true, response: 6 }

Create receiver structure

use the SigepWeb::Models::Receiver to create receiver structure:

SigepWeb::Models::Receiver.new(name: 'Josefina', email: '[email protected]',
                               number: '10', address: 'Rua X',
                               complement: 'Perto da rua X+1',
                               neighborhood: 'Bairro X-1',
                               city: 'Cidade Y', uf: 'SP', amount: '0,0',
                               cep: '04105-070')

Create post object dimensions

use the SigepWeb::Models::DimensionObject to create object dimensions:

SigepWeb::Models::DimensionObject.new(object_type: '002', height: '20',
                                      width: '30', length: '38',
                                      diameter: '0')
  • object_type: use 001 to letter envelope, 002 to package/ box and 003 to roll/ cylinder

Create post object

use the SigepWeb::Models::PostalObject to create post object:

SigepWeb::Models::PostalObject.new(label_number: 'DL611459296BR',
                                   postage_code_service: '40096',
                                   cubage: 0.0, weight: '400',
                                   receiver: receiver,
                                   dimension_object: dimension_object,
                                   processing_status: '0')
  • label_number: tracking code with verifying digit
  • postage_code: service code to use (SEDEX, PAC, etc.), for this example was used SEDEX, to get all available codes use SigepWeb.search_client
  • receiver: object instance of SigepWeb::Models::Receiver class
  • dimension_object: object instance of SigepWeb::Models::DimensionObject class
  • processing_status: default value is '0'

Create sender

SigepWeb::Models::Sender.new(directorship_number: '16', name: 'Loja X',
                             address: 'Rua X', number: '10',
                             complement: 'perto da rua X+1',
                             neighborhood: 'Bairro Y',
                             zip_code: '7400000', city: 'Goiânia',
                             uf: 'GO', email: 'contato@loja_x.com.br',
                             postal_objects: postal_objects)

Submit the plp

SigepWeb.request_plp_services(plp: sender, id_plp_client: 00_000_000,
                              labels: labels)

About

Integration with Correios Sigep Web API

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •