const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.betterez.com/sales/cart/:cartId',
  headers: {
    authorization: 'Bearer {{jwtToken}}',
    'Content-Type': 'application/json;charset=UTF-8',
    Accept: 'application/json, text/plain, */*',
    'x-api-key': '{{x-api-key}}'
  },
  body: {
    operationId: '{{some-GUID}}',
    channel: '{{a-valid-channel}}',
    providerId: '{{providerId}}',
    items: {
      parcel: [
        {
          productId: '{{productId}}',
          declaredValue: '200',
          applyInsurance: true,
          channel: 'channel',
          from: {_id: '{{originId}}'},
          to: {_id: '{{destinationId}}'},
          parcels: [
            {
              fareId: '{{fareId}}',
              weight: {unit: 'gr', value: 5000},
              measure: {
                length: {unit: 'mm', value: 150},
                width: {unit: 'mm', value: 150},
                height: {unit: 'mm', value: 150}
              }
            }
          ],
          extra: {
            from: {
              firstName: 'firstName',
              lastName: 'lastName',
              phoneNumber: '555',
              companyName: '555',
              address: 'someAddress',
              city: 'someCity',
              zipCode: '1718',
              country: {name: 'countryName', _id: '4faad0c1d4f11a3a4600005e', ISO: 'ISO'},
              province: 'someProvince'
            },
            to: {
              firstName: 'firstName',
              lastName: 'lastName',
              phoneNumber: '555',
              companyName: '555',
              address: 'someAddress',
              city: 'someCity',
              zipCode: '1718',
              country: {name: 'countryName', _id: '4faad0c1d4f11a3a4600005e', ISO: 'ISO'},
              province: 'someProvince'
            }
          }
        }
      ]
    },
    language: 'en'
  },
  json: true
};

request(options, function (error, response, body) {
	if (error) throw new Error(error);

	console.log(body);
});