Skip to content
jvdspeare edited this page Feb 19, 2019 · 7 revisions

port

Place or validate an order for a Megaport.

Usage

import megalib
x = megalib.port(header, loc_id, name, speed, market, term, validate, prod)

Arguments

header (required) String Header

loc_id (required) Integer Location ID

name (required) String Service Name

speed (required) Integer Service Speed

market (required) String Billing Market

term Integer Contract Term in Months (1, 12, 24, 36)

validate Boolean True = Validate, False = Order

prod Boolean Environment, True = https://api.megaport.com, False = https://api-staging.megaport.com

Response

x.status_code Integer HTTPS Response Status Code

x.json Integer Response

x.currency String Currency

x.monthly_rate Integer Monthly Cost

x.uid String TechnicalServiceUid

Example

source

# Import megalib
import megalib

# Authenticate user credentials using the megalib.login function
auth = megalib.login(input('username: '), input('password: '), input('tfa (leave black if not enabled): '), prod=False)

# Check if logging was successful by observing the HTTP Status Code
if auth.status_code == 200:
    print('login successful')

    # Order port using the megalib.port function
    port = megalib.port(auth.header, input('location id: '), input('service name: '), input('speed: '),
                        input('market: '), input('contract term: '), validate=False, prod=True)

    # Advise user if port order was successful
    if port.status_code == 200:
        print('port ordered successfully')

    # Advise user if port order failed
    else:
        print('port order failed')

# Advise user if login failed
else:
    print('login failed')

Megaport API documentation

Validate Port Order

Buy Port

Clone this wiki locally