sdksio-postnl-ecommerce-apis-sdk
Version:
Collection of PostNL API's for ecommerce processes
79 lines (76 loc) • 3.41 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 {
BarcodeMethodNotAllowedError,
} from '../errors/barcodeMethodNotAllowedError';
import { BarcodeResponseError } from '../errors/barcodeResponseError';
import {
BarcodeResponseInvalidError,
} from '../errors/barcodeResponseInvalidError';
import {
BarcodeTooManyRequestError,
} from '../errors/barcodeTooManyRequestError';
import {
BarcodeResponse,
barcodeResponseSchema,
} from '../models/barcodeResponse';
import { Type1Enum, type1EnumSchema } from '../models/type1Enum';
import { optional, string } from '../schema';
import { BaseController } from './baseController';
export class BarcodeController extends BaseController {
/**
* Request example:
* ```
* curl -X GET "https://api-sandbox.postnl.nl/shipment/v1_1/barcode?CustomerCode=DEVC&
* CustomerNumber=11223344&Type=3S&Serie=000000000-999999999&Range=NL" \
* -H "Accept: application/json" \
* -H "apikey: APIKEY-HERE"
* ```
*
*
* @param customerCode The customer code for which you want a barcode to be generated
* @param customerNumber The customer code for which you want a barcode to be generated
* @param type The barcode type that you want to be generated
* @param serie Barcode serie in the format '###000000-###000000', for example 100000-20000.
* The range must consist of a minimal difference of 100.000. It is allowed to add
* extra leading zeros at the beginning of the serie. See [Guidelines](https:
* //developer.postnl.nl/browse-apis/send-and-track/barcode-webservice/) for more
* information.
* @param range Only used for International Mail and Packet products (PEPS) shipments (with
* type LA, RI, UE). Identifying the issuing postal administration's country (NL
* in this case).
* @return Response from the API call
*/
async generateAUniqueBarcode(
customerCode: string,
customerNumber: string,
type: Type1Enum,
serie?: string,
range?: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<BarcodeResponse>> {
const req = this.createRequest('GET', '/shipment/v1_1/barcode');
const mapped = req.prepareArgs({
customerCode: [customerCode, string()],
customerNumber: [customerNumber, string()],
type: [type, type1EnumSchema],
serie: [serie, optional(string())],
range: [range, optional(string())],
});
req.query('CustomerCode', mapped.customerCode);
req.query('CustomerNumber', mapped.customerNumber);
req.query('Type', mapped.type);
req.query('Serie', mapped.serie);
req.query('Range', mapped.range);
req.throwOn(400, BarcodeResponseInvalidError, 'Invalid request');
req.throwOn(401, BarcodeResponseError, 'Unauthorized');
req.throwOn(405, BarcodeMethodNotAllowedError, 'Method not allowed');
req.throwOn(429, BarcodeTooManyRequestError, 'Too many requests');
req.throwOn(500, BarcodeResponseError, 'Internal server error');
return req.callAsJson(barcodeResponseSchema, requestOptions);
}
}