Cubapack Micro-Service Documentation

Endpoint

URL: https://cubapack-service.herokuapp.com/api/v2/package

Http method: POST

Payload: { shippingType, packageType, items, shipper, consignee }

Authentication

This service implement Basic Authentication Scheme which transmits credentials as email / password pairs, encoded using base64. Each request must include this authorization token in their headers otherwise the request will be rejected.

Example:

Having the next credentials, email: example@gmail.com password: mystrongpassword we need to concat email:password after that we need to encode them to base64 and concat the result with the word Basic

example@gmail.com:mystrongpassword to base64 is equal to ZXhhbXBsZUBnbWFpbC5jb206bXlzdHJvbmdwYXNzd29yZA==

After that we cancat the word Basic: Basic ZXhhbXBsZUBnbWFpbC5jb206bXlzdHJvbmdwYXNzd29yZA== and put them in the headers using the authorization scheme

Authorization: Basic ZXhhbXBsZUBnbWFpbC5jb206bXlzdHJvbmdwYXNzd29yZA==

Use this online tool to encode your credentials to base64: https://www.blitter.se/utils/basic-authentication-header-generator/

Request payload

The payload must have 5 attributes

shippingType: This param is an string with three possibles values: Palco , Aerovaradero Habana or Aerovaradero CAMAGUEY . If this attribute is missing or has different value the server response with an error {code:400, msg:'...'}

packageType: This param is an string with four possibles values: E.N.A or Paqueteria on Palco shippings and Miscelanea or Duradero on Aerovaradero shippings. If this attribute is missing or has different value the server response with an error {code:400, msg:'...'}

Example: { packageType: 'E.N.A' }

items: This param is an array of objects, each object contains 3 attributes and these attributes describe a package.

Example: items: [ { description: 'My first package description', weight: 34.5, salePrice: 60.2 }, { description: 'My second package description', weight: 10.5, salePrice: 20.8 } ]

shipper: This param contains information about the person who sends packages to Cuba. Contains 7 attributes as shown below.

Example: shipper: { name: 'Rolando', lastName: 'Betancourt', phone: '786-456-2345', address: '2950 w 5 ave', city: 'HIALEAH', zipCode: '33014', state: 'Florida', }

consignee: This param contains information about the person who receive the package in Cuba. Contains 13 attributes as shown below.

Example: consignee: { name: 'Zuniet', lastName: 'Santiesteban', ci: '93040712121', passport: 'K67677', phone: '53290190', homePhone: '', street: 'Princesa', houseNumber: '#155', between: '% Calvo y Soubervilles', apartment: '', neighborhood: '', province: 'Matanzas', municipality: 'Cárdenas', }

Validations

You must provide the basic authorization token in the headers as described earlier in this article.

Attributes can't be null or undefined, use ( 0 ) or ( " " ) instead

The attribute shippingType can only take three possible values ( 'Palco' , 'Aerovaradero Habana' or 'Aerovaradero CAMAGUEY' )

The attribute packageType can only take two possible values ( 'E.N.A' or 'Paqueteria' )on Palco shippings.

The attribute packageType can only take two possible values ( 'Miscelanea' or 'Duradero' )on Aerovaradero shippings.

When the attribute packageType == 'E.N.A' then shipper and consignee must be the same person.

When the attribute packageType == 'E.N.A' then the consignee passport attribute can't be an empty string.

When the attribute packageType == 'Paqueteria' then shipper and consignee must be different person.

Server response

Success:

If success the server response with two arrays, the items and packages created. [ code: 201 ]

Example: { itemsResult: [...], packagesResult: [...] }

Failure:

If failure the server response with an object with differents attributes related with the error. [code: 400, 401, 500]

Example: { error: { msg: {...} }, status: 400, ... }

msg attribute contains custom error details.

Make an HTTP POST request using Angular

You can use the authorization token in the above example to create package and test your implementation.

 

createPackage(): Observable {
  const headers = new HttpHeaders({
   Authorization: 'Basic cm9sYW5kbzA5MDJAZ21haWwuY29tOldjUmJUIzEz'
  });

  return this.http.post('https://cubapack-service.herokuapp.com/api/v2/package', {
   shippingType: 'Palco', packageType: 'Paqueteria',

   items: [
    {
     description: 'Freidora',
     weight: 20,
     salePrice: 39.8
    },
    {
     description: 'Bicicleta',
     weight: 33,
     salePrice: 65.67
    }
   ],

   consignee: {
    name: 'Zuniet',
    lastName: 'Santiesteban',
    ci: '93040712121',
    passport: 'K67677',
    phone: '53190720',
    homePhone: '',
    street: 'Princesa',
    houseNumber: '#155',
    between: '% Calvo y Soubervilles',
    apartment: '',
    neighborhood: '',
    province: 'Matanzas',
    municipality: 'Cárdenas',
   },

   shipper: {
    name: 'Rolando',
    lastName: 'Betancourt',
    phone: '7864405007',
    address: '3920 w 6 ave',
    city: 'HIALEAH',
    zipCode: '33014',
    state: 'Florida',
   }
  }, {
    headers
  });
}