Constructing Learning Plan URLs

Build a link that opens a learning plan on Udacity directly from Catalog API data. You can link to the whole plan, or deep-link to a specific step.

Learning plan URLs are built from the plan’s slug (not its id). Always read the slug from the Catalog API rather than hardcoding it — a plan’s slug can change.

URL Format

A learning plan opens at the following path, where {slug} is the plan’s URL-friendly identifier:

slugpath segmentRequired

The plan’s slug from the Catalog API (CatalogLearningPlan.slug).

stepquery param

Optional. The stepId to open. Pass a top-level step’s stepId directly. To open a step nested inside a container, pass the container’s stepId here and the nested step in highlight.

highlightquery param

Optional. The stepId of a step nested inside the container named in step. Only needed when deep-linking to a nested step.

The step and highlight parameters deep-link on the current learning plan layout. Linking to the plan by slug alone always opens the plan; if a step-level link ever fails to deep-link, fall back to the plan-level URL.

Whole plan
https://www.udacity.com/learning-plan/layout-v2-test-the-ultimate-edge-case-plan
Deep link to a top-level step
https://www.udacity.com/learning-plan/layout-v2-test-the-ultimate-edge-case-plan?step=2c0a4fe4-7687-43f9-b749-891e5c636a65
Deep link to a nested step
https://www.udacity.com/learning-plan/layout-v2-test-the-ultimate-edge-case-plan?step=8a386eac-5a18-4229-88a4-add7f1ee600f&highlight=b6b5e826-2f1a-4c3d-9e77-6f0d2a1b9c44

Getting the Data

Query the Catalog API for the learning plans in your company catalog. Each plan exposes a slug, and each of its steps exposes a stepId. Use a top-level step’s stepId as the step parameter; for a step nested inside a CatalogContainerStep, use the container’s stepId as step and the nested stepId as highlight.

See Catalog API — Queries for the full step structure, including nested container steps.

Query
query GetCatalog($contractId: ID) {
  catalog(contractId: $contractId) {
    learningPlans {
      id
      title
      slug
      steps {
        stepId
        stepType
        label
      }
    }
  }
}
Response
{
  "data": {
    "catalog": {
      "learningPlans": [
        {
          "id": "fd6f0490-2072-43b0-b1d0-7ee82fe96df2",
          "title": "The Ultimate Edge Case Plan",
          "slug": "layout-v2-test-the-ultimate-edge-case-plan",
          "steps": [
            { "stepId": "2c0a4fe4-7687-43f9-b749-891e5c636a65", "stepType": "PROGRAM", "label": "Cloud Architecture" }
          ]
        }
      ]
    }
  }
}

Building the URL

Append the slug to the base path. To deep-link, set the step query parameter to a top-level step’s stepId — or, for a step nested inside a container, set step to the container’s stepId and highlight to the nested step’s stepId.

JavaScript
function buildLearningPlanUrl(slug, { stepId, highlightStepId } = {}) {
  const url = new URL(`https://www.udacity.com/learning-plan/${slug}`);
  if (stepId) {
    url.searchParams.set("step", stepId);
    // Deep-linking to a step nested inside a container: pass the container's
    // stepId as "step" and the nested step's stepId as "highlight".
    if (highlightStepId) {
      url.searchParams.set("highlight", highlightStepId);
    }
  }
  return url.toString();
}

// Whole plan:
buildLearningPlanUrl("layout-v2-test-the-ultimate-edge-case-plan");
// Deep link to a top-level step:
buildLearningPlanUrl("layout-v2-test-the-ultimate-edge-case-plan", {
  stepId: "2c0a4fe4-7687-43f9-b749-891e5c636a65",
});
// Deep link to a step nested inside a container:
buildLearningPlanUrl("layout-v2-test-the-ultimate-edge-case-plan", {
  stepId: "8a386eac-5a18-4229-88a4-add7f1ee600f", // the container's stepId
  highlightStepId: "b6b5e826-2f1a-4c3d-9e77-6f0d2a1b9c44", // the nested stepId
});