sdksio-postnl-ecommerce-apis-sdk
Version:
Collection of PostNL API's for ecommerce processes
272 lines (268 loc) • 13.5 kB
text/typescript
/**
* PostNL Ecommerce APIsLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
import { ApiResponse, RequestOptions } from '../core';
import { DeliverydateResponseError } from '../errors/deliverydateResponseError';
import {
DeliverydateResponseInvalidError,
} from '../errors/deliverydateResponseInvalidError';
import {
PostCIFDeliveryDateMethodNotAllowedError,
} from '../errors/postCIFDeliveryDateMethodNotAllowedError';
import {
PostCIFDeliveryDateTooManyRequestError,
} from '../errors/postCIFDeliveryDateTooManyRequestError';
import {
PostCIFDeliveryDateUnauthorizedError,
} from '../errors/postCIFDeliveryDateUnauthorizedError';
import {
CountryCode1Enum,
countryCode1EnumSchema,
} from '../models/countryCode1Enum';
import { Option3Enum, option3EnumSchema } from '../models/option3Enum';
import {
OriginCountryCodeEnum,
originCountryCodeEnumSchema,
} from '../models/originCountryCodeEnum';
import {
ShipmentV22CalculateDateDeliveryResponse,
shipmentV22CalculateDateDeliveryResponseSchema,
} from '../models/shipmentV22CalculateDateDeliveryResponse';
import {
ShipmentV22CalculateDateShippingResponse,
shipmentV22CalculateDateShippingResponseSchema,
} from '../models/shipmentV22CalculateDateShippingResponse';
import { array, boolean, number, optional, string } from '../schema';
import { BaseController } from './baseController';
export class DeliverydateController extends BaseController {
/**
* Request example:
* ```
* curl -X GET "https://api-sandbox.postnl.nl/shipment/v2_2/calculate/date/delivery?ShippingDate=29-05-
* 2022+14%3A00%3A00&ShippingDuration=1&CutOffTime=17%3A00%3A00&PostalCode=2132WT&
* CountryCode=NL&City=Hoofddorp&Street=Siriusdreef&HouseNumber=42&HouseNrExt=A" \
* -H "Accept: application/json" \
* -H "apikey: APIKEY-HERE"
* ```
*
*
* @param shippingDate Date/time of preparing the shipment for sending. Format: dd-
* MM-yyyy hh:mm:ss
* @param shippingDuration The duration it takes for the shipment to be delivered to
* PostNL in days. A value of 1 means that the parcel will be
* delivered to PostNL on the same day as the date specified in
* ShippingDate. A value of 2 means the parcel will arrive at
* PostNL a day later etc.
* @param cutOffTime Default cutoff time
* @param postalCode Zipcode of the destination address
* @param countryCode The ISO2 destination country code
* @param options The delivery options that you want to take into account when
* calculating the expected delivery date
* @param originCountryCode The ISO2 origin country code
* @param city City of the destination address
* @param street The street name of the destination address.
* @param houseNumber The house number of the destination address
* @param houseNrExt House number extension of the delivery address
* @param cutOffTimeMonday Overrides default cutoff time specified in the CutOffTime
* parameter for mondays specifically
* @param availableMonday Specifies if you are available to ship to PostNL on mondays
* @param cutOffTimeTuesday Overrides default cutoff time specified in the CutOffTime
* parameter for tuesdays specifically
* @param availableTuesday Specifies if you are available to ship to PostNL on tuesdays
* @param cutOffTimeWednesday Overrides default cutoff time specified in the CutOffTime
* parameter for wednesdays specifically
* @param availableWednesday Specifies if you are available to ship to PostNL on
* wednesdays
* @param cutOffTimeThursday Overrides default cutoff time specified in the CutOffTime
* parameter for thursdays specifically
* @param availableThursday Specifies if you are available to ship to PostNL on
* thursdays
* @param cutOffTimeFriday Overrides default cutoff time specified in the CutOffTime
* parameter for fridays specifically
* @param availableFriday Specifies if you are available to ship to PostNL on fridays
* @param cutOffTimeSaturday Overrides default cutoff time specified in the CutOffTime
* parameter for saturdays specifically
* @param availableSaturday Specifies if you are available to ship to PostNL on
* saturdays
* @param cutOffTimeSunday Overrides default cutoff time specified in the CutOffTime
* parameter for sundays specifically
* @param availableSunday Specifies if you are available to ship to PostNL on sundays
* @return Response from the API call
*/
async calculateExpectedDeliveryDate(
shippingDate: string,
shippingDuration: number,
cutOffTime: string,
postalCode: string,
countryCode: CountryCode1Enum,
options: Option3Enum[],
originCountryCode?: OriginCountryCodeEnum,
city?: string,
street?: string,
houseNumber?: number,
houseNrExt?: string,
cutOffTimeMonday?: string,
availableMonday?: boolean,
cutOffTimeTuesday?: string,
availableTuesday?: boolean,
cutOffTimeWednesday?: string,
availableWednesday?: boolean,
cutOffTimeThursday?: string,
availableThursday?: boolean,
cutOffTimeFriday?: string,
availableFriday?: boolean,
cutOffTimeSaturday?: string,
availableSaturday?: boolean,
cutOffTimeSunday?: string,
availableSunday?: boolean,
requestOptions?: RequestOptions
): Promise<ApiResponse<ShipmentV22CalculateDateDeliveryResponse>> {
const req = this.createRequest(
'GET',
'/shipment/v2_2/calculate/date/delivery'
);
const mapped = req.prepareArgs({
shippingDate: [shippingDate, string()],
shippingDuration: [shippingDuration, number()],
cutOffTime: [cutOffTime, string()],
postalCode: [postalCode, string()],
countryCode: [countryCode, countryCode1EnumSchema],
options: [options, array(option3EnumSchema)],
originCountryCode: [
originCountryCode,
optional(originCountryCodeEnumSchema),
],
city: [city, optional(string())],
street: [street, optional(string())],
houseNumber: [houseNumber, optional(number())],
houseNrExt: [houseNrExt, optional(string())],
cutOffTimeMonday: [cutOffTimeMonday, optional(string())],
availableMonday: [availableMonday, optional(boolean())],
cutOffTimeTuesday: [cutOffTimeTuesday, optional(string())],
availableTuesday: [availableTuesday, optional(boolean())],
cutOffTimeWednesday: [cutOffTimeWednesday, optional(string())],
availableWednesday: [availableWednesday, optional(boolean())],
cutOffTimeThursday: [cutOffTimeThursday, optional(string())],
availableThursday: [availableThursday, optional(boolean())],
cutOffTimeFriday: [cutOffTimeFriday, optional(string())],
availableFriday: [availableFriday, optional(boolean())],
cutOffTimeSaturday: [cutOffTimeSaturday, optional(string())],
availableSaturday: [availableSaturday, optional(boolean())],
cutOffTimeSunday: [cutOffTimeSunday, optional(string())],
availableSunday: [availableSunday, optional(boolean())],
});
req.query('ShippingDate', mapped.shippingDate);
req.query('ShippingDuration', mapped.shippingDuration);
req.query('CutOffTime', mapped.cutOffTime);
req.query('PostalCode', mapped.postalCode);
req.query('CountryCode', mapped.countryCode);
req.query('Options', mapped.options);
req.query('OriginCountryCode', mapped.originCountryCode);
req.query('City', mapped.city);
req.query('Street', mapped.street);
req.query('HouseNumber', mapped.houseNumber);
req.query('HouseNrExt', mapped.houseNrExt);
req.query('CutOffTimeMonday', mapped.cutOffTimeMonday);
req.query('AvailableMonday', mapped.availableMonday);
req.query('CutOffTimeTuesday', mapped.cutOffTimeTuesday);
req.query('AvailableTuesday', mapped.availableTuesday);
req.query('CutOffTimeWednesday', mapped.cutOffTimeWednesday);
req.query('AvailableWednesday', mapped.availableWednesday);
req.query('CutOffTimeThursday', mapped.cutOffTimeThursday);
req.query('AvailableThursday', mapped.availableThursday);
req.query('CutOffTimeFriday', mapped.cutOffTimeFriday);
req.query('AvailableFriday', mapped.availableFriday);
req.query('CutOffTimeSaturday', mapped.cutOffTimeSaturday);
req.query('AvailableSaturday', mapped.availableSaturday);
req.query('CutOffTimeSunday', mapped.cutOffTimeSunday);
req.query('AvailableSunday', mapped.availableSunday);
req.throwOn(400, DeliverydateResponseInvalidError, 'Bad request');
req.throwOn(401, PostCIFDeliveryDateUnauthorizedError, 'Invalid apikey');
req.throwOn(405, PostCIFDeliveryDateMethodNotAllowedError, 'Method not allowed');
req.throwOn(429, PostCIFDeliveryDateTooManyRequestError, 'Too many requests');
req.throwOn(500, DeliverydateResponseError, 'Internal server error');
return req.callAsJson(
shipmentV22CalculateDateDeliveryResponseSchema,
requestOptions
);
}
/**
* Request example:
* ```
* curl -X GET "https://api-sandbox.postnl.nl/shipment/v2_2/calculate/date/shipping?DeliveryDate=30-05-
* 2022&ShippingDuration=1&PostalCode=2132WT&CountryCode=NL&City=Hoofddorp&
* Street=Siriusdreef&HouseNumber=42&HouseNrExt=A" \
* -H "Accept: application/json" \
* -H "apikey: APIKEY-HERE" \
*
* ```
*
*
* @param deliveryDate Date of the expected delivery (to the final destination) of the
* shipment.
* @param shippingDuration The duration it takes for the shipment to be delivered to
* PostNL in days. A value of 1 means that the parcel will be
* delivered to PostNL on the same day as the date specified in
* ShippingDate. A value of 2 means the parcel will arrive at
* PostNL a day later etc.
* @param postalCode Zipcode of the address
* @param countryCode The ISO2 destination country code
* @param originCountryCode The ISO2 country code of the origin country
* @param city City of the destination address
* @param street The street name of the destination address
* @param houseNumber The house number of the destination address
* @param houseNrExt House number extension of the destination address
* @return Response from the API call
*/
async calculateRequiredShippingDate(
deliveryDate: string,
shippingDuration: number,
postalCode: string,
countryCode: CountryCode1Enum,
originCountryCode?: OriginCountryCodeEnum,
city?: string,
street?: string,
houseNumber?: number,
houseNrExt?: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<ShipmentV22CalculateDateShippingResponse>> {
const req = this.createRequest(
'GET',
'/shipment/v2_2/calculate/date/shipping'
);
const mapped = req.prepareArgs({
deliveryDate: [deliveryDate, string()],
shippingDuration: [shippingDuration, number()],
postalCode: [postalCode, string()],
countryCode: [countryCode, countryCode1EnumSchema],
originCountryCode: [
originCountryCode,
optional(originCountryCodeEnumSchema),
],
city: [city, optional(string())],
street: [street, optional(string())],
houseNumber: [houseNumber, optional(number())],
houseNrExt: [houseNrExt, optional(string())],
});
req.query('DeliveryDate', mapped.deliveryDate);
req.query('ShippingDuration', mapped.shippingDuration);
req.query('PostalCode', mapped.postalCode);
req.query('CountryCode', mapped.countryCode);
req.query('OriginCountryCode', mapped.originCountryCode);
req.query('City', mapped.city);
req.query('Street', mapped.street);
req.query('HouseNumber', mapped.houseNumber);
req.query('HouseNrExt', mapped.houseNrExt);
req.throwOn(400, DeliverydateResponseInvalidError, 'Bad request');
req.throwOn(401, PostCIFDeliveryDateUnauthorizedError, 'Invalid apikey');
req.throwOn(405, PostCIFDeliveryDateMethodNotAllowedError, 'Method not allowed');
req.throwOn(429, PostCIFDeliveryDateTooManyRequestError, 'Too many requests');
req.throwOn(500, DeliverydateResponseError, 'Internal server error');
return req.callAsJson(
shipmentV22CalculateDateShippingResponseSchema,
requestOptions
);
}
}