# How to attach an app to a hosting plan (https://developer.godaddy.com/en/docs/api-users/hosting/attach-hosting-plan)

---
title: How to attach an app to a hosting plan
description: Attach your app to a web hosting subscription to enable publishing.
keywords: >-
  PUT /apps/{appId}/subscription, attach app subscription, hosting plan, web
  hosting, hosting.subscription:write
agentNotes:
  scopes:
    - 'hosting.subscription:write'
  idempotent: true
  destructive: false
  failureRecovery: >-
    Attachment is synchronous. Verify the subscription ID exists on your account
    and the app is already created.
related:
  tutorials:
    - title: Deploy your Node.js app
      href: /docs/api-users/hosting/workflows/deploy-nodejs-app
  guides:
    - title: Manage apps
      href: /docs/api-users/hosting/manage-apps
  concepts:
    - title: Hosting concepts
      href: /docs/api-users/hosting/concepts
  apis:
    - title: Hosting API reference
      href: /docs/references/rest/hosting
pageId: edd61aa6-e571-43c4-86ac-d336abc02435
---

## Overview

Subscription attachment is required before going live for Node.js apps.

Before you can publish a Node.js app to production, you must attach it to a web hosting subscription. This operation is synchronous and returns immediately on success.

WordPress sites (`MHWP-` ids) live inside an Airo App Builder subscription and need no hosting plan. `GET` and `PUT /v1/hosting/apps/{appId}/subscription` return `501 NOT_APPLICABLE` for them.

Subscriptions are purchased separately in your GoDaddy account. After attachment, the app is bound to that subscription's infrastructure and billing. This article describes how to attach a hosting plan to your web app.

Go to [Deploy your Node.js app](https://developer.godaddy.com/docs/api-users/hosting/workflows/deploy-nodejs-app) for the full deployment walkthrough (which includes this procedure).

## Prerequisites

The following prerequisites are required before you can attach a hosting plan to your app:

* a [Personal Access Token](https://developer.godaddy.com/personal-access-token) with the `hosting.subscription:write` scope
* a hosting app already created

  Go to [Deploy your Node.js app](https://developer.godaddy.com/docs/api-users/hosting/workflows/deploy-nodejs-app) for instructions to create a hosting app.
* a web hosting subscription ID from your GoDaddy account

## Attach an app to a subscription

`PUT /apps/{appId}/subscription` attaches a created app to a hosting plan. The subscription must belong to your account and have available capacity. Success returns `200 OK` with the subscription attachment details. After you complete this procedure, you can publish your app.

* Attach the app:

  ```bash tab="curl"
  curl -s -X PUT "$BASE_URL/v1/hosting/apps/$APP_ID/subscription" \
    -H "Authorization: Bearer $GODADDY_PAT" \
    -H "Content-Type: application/json" \
    -d '{ "subscriptionId": "'$SUBSCRIPTION_ID'" }'
  ```

  ```js tab="Node"
  const res = await fetch(`${process.env.BASE_URL}/v1/hosting/apps/${appId}/subscription`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${process.env.GODADDY_PAT}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ subscriptionId }),
  });

  if (!res.ok) {
    console.error(`Error: ${res.status}`);
    return;
  }

  const result = await res.json();
  console.log('Attachment successful', result);
  ```

  ```python tab="Python"
  import requests, os

  resp = requests.put(
      f"{os.environ['BASE_URL']}/v1/hosting/apps/{app_id}/subscription",
      headers={"Authorization": f"Bearer {os.environ['GODADDY_PAT']}"},
      json={"subscriptionId": subscription_id},
  )

  if resp.status_code != 200:
      print(f"Error: {resp.status_code}")
      exit(1)

  result = resp.json()
  print("Attachment successful", result)
  ```

  ```go tab="Go"
  body := strings.NewReader(`{"subscriptionId":"` + subscriptionID + `"}`)
  req, _ := http.NewRequest("PUT",
      os.Getenv("BASE_URL")+"/v1/hosting/apps/"+appID+"/subscription",
      body)
  req.Header.Set("Authorization", "Bearer "+os.Getenv("GODADDY_PAT"))
  req.Header.Set("Content-Type", "application/json")
  resp, _ := http.DefaultClient.Do(req)
  defer resp.Body.Close()

  if resp.StatusCode != 200 {
      fmt.Printf("Error: %d\n", resp.StatusCode)
      return
  }

  var result map[string]interface{}
  json.NewDecoder(resp.Body).Decode(&result)
  fmt.Println("Attachment successful", result)
  ```

## Common errors

The following table lists common errors when attaching:

| Status | Cause                                     | Action                                                                                                                  |
| ------ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `400`  | Invalid app ID or subscription ID         | Verify both IDs are correct and belong to your account                                                                  |
| `401`  | Expired or revoked PAT, or missing scope  | Go to [Hosting core concepts](https://developer.godaddy.com/docs/api-users/hosting/concepts#scopes-reference) for the scopes you need                |
| `404`  | App or subscription not found             | Confirm the app exists and the subscription ID is on your account                                                       |
| `409`  | No capacity available on the subscription | The subscription has no available capacity. Verify the subscription supports additional apps or contact GoDaddy support |
