> ## Documentation Index
> Fetch the complete documentation index at: https://docs.megaport.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating a Port with the API

> This help topic describes how to use the Megaport API to create a Megaport.

export const Gloss = ({term, anchor, langDir = 'en'}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Gloss -';
  if (typeof term !== 'string') {
    term = String(term);
  }
  if (typeof anchor !== 'string') {
    anchor = String(anchor);
  }
  if (!term || term === 'undefined') {
    console.error(`${errorPrefix} the \`term\` property is required — rendering an empty string instead`);
    return <></>;
  }
  if (!anchor || anchor === 'undefined') {
    console.error(`${errorPrefix} the \`anchor\` property is required — rendering an empty string instead`);
    return <></>;
  }
  const lang = langDir === 'en' ? '/' : '/' + langDir + '/';
  const glossaryPage = lang + 'glossary/#' + anchor;
  return <a href={glossaryPage}>{term}</a>;
};

export const Image = ({src, alt = '', caption, width, height, shadow}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Image -';
  if (typeof src !== 'string') {
    src = String(src);
  }
  if (!src || src === 'undefined') {
    console.error(`${errorPrefix} \`src\` is required — rendering an empty string instead`);
    return <></>;
  }
  const img = <img className={['mega-image-style', shadow ? 'shadow' : ''].join(' ')} src={src} alt={alt} width={width} height={height} style={{
    display: 'block'
  }} />;
  return caption ? <figure>
      {img}
      <figcaption style={{
    textAlign: 'center',
    width
  }}>{caption}</figcaption>
    </figure> : img;
};

This topic describes the API procedure to create a Port, including how to look up Port locations, validate the Port and determine the cost, order the Port, and download the <Gloss term="Letter of Authorization (LOA)" anchor="loa" />.

Before you begin, obtain a valid access token. For more information, see [Creating an API Key](/api/api-key).

**To look up Port location details in the Postman collection**

1. Click **Locations** in the left navigation and click **GET Locations (v3)**.\
   This request is not expecting Parameters or Body information.

2. Click **Send** to make the request.

   ```http theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
   GET {baseUrl}/v3/locations
   ```

   <Image src="/images/api/get-locations.png" alt="Get locations" shadow={true} width={800} />

   Ensure the request was successful by looking for Status: 200 OK and display the response in the Body section in the Pretty format.

   The request returns hundreds of Port locations. You can search by clicking the magnifying glass and entering a specific city, data center, or other parameter in the search field. This example uses the Digital Realty, London location.

```json {2,17} theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
            "id": 89,
            "name": "Digital Realty London LHR20",
            "address": {
                "street": "227 Marsh Wall",
                "suburb": null,
                "city": "London",
                "state": null,
                "postcode": "E14 9SD",
                "country": "United Kingdom"
            },
            "dataCentre": {
                "id": 3,
                "name": "Digital Realty"
            },
            "metro": "London",
            "market": "UK",
            "status": "Active",
            "longitude": -0.012144,
            "latitude": 51.499714,
            "orderingMessage": null,
            "diversityZones": {
                "red": {
                    "mcrSpeedMbps": [
                        5000,
                        100000,
                        1000,
                        25000,
                        10000,
                        2500,
                        50000
                    ],
                    "megaportSpeedMbps": [
                        100000,
                        10000,
                        1000
                    ],
                    "mveMaxCpuCoreCount": null,
                    "mveAvailable": true
                },
                "blue": {
                    "mcrSpeedMbps": [
                        1000,
                        2500,
                        5000,
                        10000
                    ],
                    "megaportSpeedMbps": [
                        1000,
                        10000,
                        100000
                    ],
                    "mveMaxCpuCoreCount": null,
                    "mveAvailable": true
                }
            },
            "productAddOns": {
                "crossConnect": {
                    "available": false,
                    "type": null
                }
            }
        }
```

To create a Port, you need the `market` value and `id` value. In this example, the market is UK and the data center ID is 89.

**To test and validate the Port order**

1. In Postman, open the **Ports** folder in the left navigation and select **POST Validate Port Order (v3)**.

2. Update the Body with the `locationId` (89), `term` (number of months - 1, 12, 24, 36, 48, or 60), `productName` (whatever name you want for your Port), `portSpeed` (1000, 10000, or 100000 Mbps), and `market` (UK) and click **Send**.

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
[
  {
    "locationId": 89,
    "term": 1,
    "locationUid": null,
    "productName": "API Port",
    "productType": "MEGAPORT",
    "createDate": 1452475039656,
    "portSpeed": 1000,
    "virtual": false,
    "promoCode": "promox3mnthfree2",
    "market": "UK"
  }
]
```

A successful response passes validation and has a 200 OK status. The response also includes pricing details of the service.

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
    "message": "Validation passed",
    "terms": "This data is subject to the Acceptable Use Policy https://www.megaport.com/legal/acceptable-use-policy",
    "data": [
        {
            "price": {
                "hourlySetup": 0,
                "dailySetup": 0,
                "monthlySetup": 0,
                "hourlyRate": 0,
                "dailyRate": 0,
                "monthlyRate": 500.00,
                "fixedRecurringCharge": 500.00,
                "postPaidBaseRate": "no base rate",
                "longHaulMbpsRate": 0,
                "mbpsRate": 0,
                "currency": "GBP",
                "key": "no key",
                "productType": "MEGAPORT",
                "empty": false
            },
            "serviceName": "API Port",
            "productType": "MEGAPORT",
            "productUid": "f9859fd3-344d-4a33-8cd2-a3b6ebfaaef0",
            "market": "UK",
            "string": "London"
        }
    ]
}
```

**To order the validated Port**

1. With a validated Port request and reviewed cost information, copy the Body from **POST Validate Port Order (v3)** and paste into the Body of **POST Buy Port (v3)**.

   <Callout icon="triangle-exclamation" color="red">
     If you make this call on api.megaport.com, your account will be charged for the service. Alternatively, you can provision against the staging API without charges, as in these examples.
   </Callout>

2. Send the request.\
   A successful response includes a `technicalServiceUid`, which is the same as the `productUid`.\
   For our example, this value is a49cf3f1-20a1-4390-93aa-5005bdafe3d7.

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
    "message": "MEGAPORT [a49cf3f1-20a1-4390-93aa-5005bdafe3d7] created. ",
    "terms": "This data is subject to the Acceptable Use Policy https://www.megaport.com/legal/acceptable-use-policy",
    "data": [
        {
            "serviceName": "API Port",
            "name": "API Port",
            "secondaryName": null,
            "technicalServiceId": 68124,
            "technicalServiceUid": "a49cf3f1-20a1-4390-93aa-5005bdafe3d7",
            "requestedDate": 1588862976322,
            "configuredDate": null,
            "currentEstimatedDelivery": null,
            "companyName": "Megaport Lab",
            "companyId": 2278,
            "aggregationId": null,
            "lagPrimary": false,
            "billingContactName": null,
            "billingContactId": null,
            "adminContactName": null,
            "adminContactId": null,
            "technicalContactName": null,
            "technicalContactId": null,
            "salesName": null,
            "salesId": null,
            "billableId": 56333,
            "billableUsageAlgorithm": "NOT_POST_PAID",
            "productType": "MEGAPORT",
            "provisioningStatus": "DEPLOYABLE",
            "inAdvanceBillingStatus": "NOT_ACTIVATED",
            "provisioningItems": [],
            "tags": [],
            "vxcDistanceBand": null,
            "intercapPath": null,
            "marketplaceVisibility": true,
            "vxcPermitted": true,
            "vxcAutoApproval": false,
            "createDate": 1588862976322,
            "terminationDate": null,
            "contractStartDate": 1588860000000,
            "contractTermMonths": 1,
            "rateType": "MONTHLY",
            "trialAgreement": false,
            "payerCompanyId": null,
            "nonPayerCompanyId": null,
            "minimumSpeed": null,
            "maximumSpeed": null,
            "rateLimit": 10000,
            "errorMessage": null,
            "market": "UK",
            "accountManager": null,
            "promptUid": null,
            "components": [],
            "attributes": [],
            "aLocation": null,
            "bLocation": null,
            "aLocationId": null,
            "bLocationId": null,
            "attributeTags": {},  
            "createdBy":  "a51cc1c6-95a0-48c7-a5a0-e49d77a6c536",
            "buyoutPort": false,
            "virtual": false,
            "locked": false,
            "adminLocked": false
        }
    ]
}
```

The new Port now appears in your working environment, either portal.megaport.com or portal-staging.megaport.com.

<Image src="/images/api/new-api-port.png" alt="New API Port" shadow={true} width={700} />

<Tip>
  To see all options for the requests used in this example, see [https://dev.megaport.com](https://dev.megaport.com).
</Tip>

## Download the Letter of Authorization (LOA)

After you create your Port, you can download the LOA.

<Note>
  Before you can download the LOA, the Provisioning Status of the Port must be Configured.
</Note>

**To download the LOA**

1. In Postman, expand **Ports** in the left navigation and select **GET Regenerate LOA for Megaport Service**.

2. In the GET command, replace the `productID` with the value created during Port creation.

3. Send the request.

   With a successful 200 OK response, this message appears in the Body section:

   ```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
   This response could not be previewed. 
   Download the response to open it with an appropriate application. 
   ```

   This message appears because the LOA is a PDF document and must be downloaded. To download, click **Save Response** in Postman and save the PDF to a convenient location.
