The StackPath Developer Portal

Integrate our platform directly into your products and dynamically protect your edge.

Get Started    API Reference

Creating your first CDN Site

Prerequisite

Review the previous Getting Started guides before continuing to ensure you have the necessary access_token and Stack . Start at the Introduction to follow along!

Now that you have all the necessary information, it's time to create a request to the API.

Creating a site

To create a site, use the /sites endpoint of the StackPath API. First, replace the stack_slug in the API call URL and access_token in the Authorization header with the values acquired in the previous steps. Next, execute the example to create your first CDN site.

Replacing example.com

Due to the requirement of a unique identifier for each domain and hostname, you must replace them with your identifier to avoid a collision error.

curl -X POST https://gateway.stackpath.com/delivery/v1/stacks/stack_slug/sites \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer access_token" \
  -d '{
    "domain": "example.com",
    "origin": {
      "path": "/",
      "hostname": "example.com",
      "port": 80,
      "securePort": 443
    },
    "features": [
      "CDN"
    ]
  }'

On success, a response returns a JSON as follows (some data is obfuscated, such as the IDs):

{
  "site": {
    "id": "00000000-0000-0000-0000-000000000000",
    "stackId": "00000000-0000-0000-0000-000000000000",
    "label": "example.com",
    "status": "ACTIVE",
    "features": [
      "CDN"
    ],
    "apiLoginUrls": [],
    "shieldPopCodes": [],
    "createdAt": "2020-02-02T01:20:20.000000Z",
    "updatedAt": "2020-02-02T01:20:20.000000Z",
    "apiUrls": [],
    "monitoring": false
  }
}

Site ID

You should see an id value within the site JSON object in the API call response. Save this for a later example.

That's it! You've made your first request using the StackPath API. If you want to go a step further with this example, keep reading. Otherwise, you've graduated to exploring on your own.

Retrieving your created site

There are a few ways to get information on the site you just created, for instance:

  • Log in to the StackPath customer portal, select the appropriate stack, then look at your Sites panel in the dashboard.
  • Call the API to retrieve the information. To use the API, first, substitute the access_token, stack_slug, and your newly created site_id with the values you've collected so far in the following example, again using the Sites endpoint:
curl -X GET https://gateway.stackpath.com/delivery/v1/stacks/stack_slug/sites/site_id \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer access_token"

On success, you receive a JSON response that looks very similar to what we got when you created the site (some data is obfuscated, such as the IDs):

{
  "site": {
    "id": "00000000-0000-0000-0000-000000000000",
    "stackId": "00000000-0000-0000-0000-000000000000",
    "label": "example.com",
    "status": "ACTIVE",
    "features": [
      "CDN"
    ],
    "apiLoginUrls": [],
    "shieldPopCodes": [],
    "createdAt": "2020-02-02T01:20:20.000000Z",
    "updatedAt": "2020-02-02T01:20:20.000000Z",
    "apiUrls": [],
    "monitoring": false
  }
}

To learn more details of the data available, review the get site reference. Well done!

Now you've expanded your usage of the API two-fold. Go forth and explore what the API has to offer by using the stack_slug and access_token with the examples provided in the api reference.

Troubleshooting

If you are getting errors, first make sure the appropriate elements of the curl command were substituted. Secondly, ensure the characters aren't formatted versions of single-quotes or double-quotes; a common formatting issue faced when moving between text editors.

If you're still stuck, contact our 24/7 support team for immediate assistance. They're here to help!

Next steps

You may be wondering when you'd want to use the API if you have access to creating a CDN site via the StackPath control portal. This depends on your use case and the automated systems you have in place for your operation. A few examples include, but are not limited to CI/CD pipeline, hosting service automation, automated scaling optimizations, and metrics gathering.

The StackPath Integrations team will expand upon these use cases in future guides and focus on providing in-depth scenarios to empower further optimizations of your DevOps systems. If you have a request, use case, or interest in contributing, please send us an email. We'd love to hear from you!

Updated 15 days ago

Creating your first CDN Site


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.