sdksio-postnl-ecommerce-apis-sdk
Version:
Collection of PostNL API's for ecommerce processes
109 lines (106 loc) • 4.64 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 {
PostCIFTimeframeMethodNotAllowedError,
} from '../errors/postCIFTimeframeMethodNotAllowedError';
import {
PostCIFTimeframeTooManyRequestError,
} from '../errors/postCIFTimeframeTooManyRequestError';
import {
PostCIFTimeframeUnauthorizedError,
} from '../errors/postCIFTimeframeUnauthorizedError';
import { TimeframeResponseError } from '../errors/timeframeResponseError';
import {
TimeframeResponseInvalidError,
} from '../errors/timeframeResponseInvalidError';
import {
CountryCode1Enum,
countryCode1EnumSchema,
} from '../models/countryCode1Enum';
import { Options1Enum, options1EnumSchema } from '../models/options1Enum';
import {
TimeframeResponse,
timeframeResponseSchema,
} from '../models/timeframeResponse';
import { array, boolean, number, optional, string } from '../schema';
import { BaseController } from './baseController';
export class TimeframesController extends BaseController {
/**
* Request example:
* ```
* curl -X GET "https://api-sandbox.postnl.nl/shipment/v2_1/calculate/timeframes?
* AllowSundaySorting=false&StartDate=30-06-2022&EndDate=02-07-
* 2022&CountryCode=NL&PostalCode=2132WT&HouseNumber=42&HouseNrExt=A&City=Hoofddorp&Street=Siriusdreef&
* Options=Daytime%2CEvening" \
* -H "Accept: application/json" \
* -H "apikey: APIKEY-HERE" \
* ```
*
*
* @param allowSundaySorting Whether or not the requesting party allows for Sunday sorting
* (which leads to delivery on Monday).
* @param startDate Date of the beginning of the timeframe. Format: dd-MM-yyyy
* @param endDate Date of the enddate of the timeframe. Format:dd-MM-yyyy. Enddate
* may not be before StartDate.
* @param countryCode The ISO2 country code of the delivery address
* @param postalCode Zipcode of the delivery address
* @param houseNumber The house number of the delivery address
* @param options The delivery options for which expected timeframes should be
* calculated. At least one delivery option must be specified. Multiple
* values should be comma-separated.
* @param houseNrExt House number extension of the delivery address
* @param city City of the delivery address
* @param street The street name of the delivery address
* @return Response from the API call
*/
async retrieveExpectedDeliveryTimeframes(
allowSundaySorting: boolean,
startDate: string,
endDate: string,
countryCode: CountryCode1Enum,
postalCode: string,
houseNumber: number,
options: Options1Enum[],
houseNrExt?: string,
city?: string,
street?: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<TimeframeResponse>> {
const req = this.createRequest(
'GET',
'/shipment/v2_1/calculate/timeframes'
);
const mapped = req.prepareArgs({
allowSundaySorting: [allowSundaySorting, boolean()],
startDate: [startDate, string()],
endDate: [endDate, string()],
countryCode: [countryCode, countryCode1EnumSchema],
postalCode: [postalCode, string()],
houseNumber: [houseNumber, number()],
options: [options, array(options1EnumSchema)],
houseNrExt: [houseNrExt, optional(string())],
city: [city, optional(string())],
street: [street, optional(string())],
});
req.query('AllowSundaySorting', mapped.allowSundaySorting);
req.query('StartDate', mapped.startDate);
req.query('EndDate', mapped.endDate);
req.query('CountryCode', mapped.countryCode);
req.query('PostalCode', mapped.postalCode);
req.query('HouseNumber', mapped.houseNumber);
req.query('Options', mapped.options);
req.query('HouseNrExt', mapped.houseNrExt);
req.query('City', mapped.city);
req.query('Street', mapped.street);
req.throwOn(400, TimeframeResponseInvalidError, 'Invalid request');
req.throwOn(401, PostCIFTimeframeUnauthorizedError, 'Unauthorized');
req.throwOn(405, PostCIFTimeframeMethodNotAllowedError, 'Method not allowed');
req.throwOn(429, PostCIFTimeframeTooManyRequestError, 'Too many requests');
req.throwOn(500, TimeframeResponseError, 'Invalid request');
return req.callAsJson(timeframeResponseSchema, requestOptions);
}
}