0.9.0 • Published 2 months ago

akamai-api-tools v0.9.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

Akamai API Tools

Library to facilitate using Akamai {OPEN} APIs


Prerequisites:

Local .edgerc file with valid Akamai client API credentials (Authenticate with EdgeGrid)


Functions

getDatesRelative(endDateOffset = 0, daysPrior = 1, returnEndDateObj = false)

 

Returns formatted start/end timestamps for a range of days

Input

ParameterTypeDescription
endDateOffsetIntDays prior to today for end date (e.g. 0 = through midnight today UTC)
daysPriorIntNumber of days prior to endDate to include in report (e.g. 1 day, 5 days, etc.)
returnDateObjBooleanInclude endDate Date object in response array

 

Output (array)

TypeDescription
StringFormatted timestamp for start of period
StringFormatted timestamp for end of period
Date objectDate object equivalent for end period

 

getDatesToFriday(weeksBack = 0, weeks = 1, returnEndDateObj = false)

 

Custom use case: Report is run each week between Monday - Thursday morning for the prior week ending last Friday (a buffer since data for prior two days is not final)

Input

ParameterTypeDescription
weeksBackIntWeeks prior to last week (0 = last week ending Friday)
weeksIntNumber of weeks prior to endDate to include in report
returnDateObjBooleanInclude endDate Date object in response array

 

Output (array)

TypeDescription
StringFormatted timestamp for start of period
StringFormatted timestamp for end of period
Date objectDate object equivalent for end period

 

async getTopCpcodes(accountSwitchKey, startDateFormatted, endDateFormatted, count=10, measurement='hits', level='edge', products=[])

 

Returns the top CP codes by hits or bytes for a given time period

Input

ParameterTypeDescription
accountSwitchKeyStringSend empty '' value if not known which default to own account
startDateFormattedStringFormatted Akamai API timestamp for start of reporting period
endDateFormattedStringFormatted Akamai API timestamp for end of reporting period
countIntnumber of CP codes to return in array
measurementString'hits' or 'bytes'
levelString'edge' or 'origin'
productsArrayLimit reporting data to specific products e.g. 'Ion Standard'

 

Output (array)

TypeDescription
ObjectLog details from API request
ArrayArray of top CP code IDs

 

async getReportData(reqObj)

 

Get content from an Akamai {OPEN} API

Input (object)

Object keyTypeDescription
pathStringAPI endpoint path
methodStringGET or POST
accountSwitchKeyStringIgnore if not known (for Akamai employees)
bodyObjectVaries by API, may be an empty but is required — see Tech Docs for details
dataPropertyStringJSON key within response to return (E.g. 'data')
paramsStringOptional: List of additional URL parameters unique to a specific API
startDateStringRequired if needed by API -- see Tech Docs for details
endDateStringRequired if needed by API -- see Tech Docs for details
intervalStringRequired if needed by API -- see Tech Docs for details
groupIdStringRequired if needed by API -- see Tech Docs for details
contractIdStringRequired if needed by API -- see Tech Docs for details
headersStringOptional: Additional headers which can change response (E.g. 'PAPI-Use-Prefixes': false)
arrayToObjectBooleanOptional: Return object instead of array
objectKeyStringRequired if arrayToObject is true, specifies what value in each array to use as object key

 

Output (array)

TypeDescription
ObjectLog details from API request
Array or ObjectAPI response, limited to the object property identified in 'dataProperty' request object

 

Sample request for account CP codes (response: object)

const cpcodeDetails = await apiTools.getReportData({
	path: '/cprg/v1/cpcodes',
	method: 'GET',
	accountSwitchKey: '',
	body: {},
	dataProperty: 'cpcodes',
	arrayToObject: true,
	objectKey: 'cpcodeId'
});

Sample request for property (response: array)

const propertyHostnames = await apiTools.getReportData({
	path: `/papi/v1/properties/${property.propertyId}/versions/${propertyVersion}/hostnames`,
	method: 'GET',
	headers: {'PAPI-Use-Prefixes': false},
	accountSwitchKey: '',
	groupId: property.groupId,
	contractId: property.contractId,
	body: {},
	dataProperty: 'hostnames.items'
});

 

getProductName(productId)

 

Convert Property Mananger API (PAPI) product ID to a human-friendly product name

Input

ParameterTypeDescription
productIdStringPAPI product ID (E.g. 'Fresca')

 

Output (array)

TypeDescription
StringHuman-friendly product name (E.g. 'Ion Standard')

 

getLength(input)

 

Standard method to get length of variable which can be an string, array, or object

Input

ParameterTypeDescription
inputString, Array, or ObjectVariable to determine length

 

Output (array)

TypeDescription
IntLegnth of string, number of array elements, or number of object keys

 

0.9.0

2 months ago

0.8.0

1 year ago

0.7.0

1 year ago

0.5.0

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.4.0

2 years ago

0.1.0

2 years ago