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

# Attach a network to a VM

> Attaches a virtual network (VLAN) to a Virtual Machine. Work runs asynchronously and returns 202 Accepted.




## OpenAPI

````yaml https://spec.speakeasy.com/latitude/latitude/latitude-sh-api-with-code-samples post /virtual_machines/{virtual_machine_id}/network_attachments
openapi: 3.0.1
info:
  title: Latitude.sh API
  version: '2023-06-01'
  description: >-
    The Latitude.sh API is a RESTful API to manage your Latitude.sh account. It
    allows you to perform the same actions as the Latitude.sh dashboard.
servers:
  - url: https://api.latitude.sh
    variables:
      latitude_api_key:
        default: <insert your api key here>
  - url: http://api.latitude.sh
    variables:
      latitude_api_key:
        default: <insert your api key here>
security: []
tags:
  - name: API keys
  - name: Billing
  - name: Elastic Ips
  - name: Events
  - name: Firewalls
  - name: IP Addresses
  - name: Kubernetes Clusters
  - name: Operating Systems
  - name: Plans
  - name: Private Networks
  - name: Projects
  - name: Regions
  - name: Roles
  - name: SSH Keys
  - name: Servers
  - name: Block Storage
  - name: Filesystem Storage
  - name: Object Storage
  - name: Tags
  - name: Teams
  - name: Team members
  - name: Traffic
  - name: User data
  - name: User profile
  - name: VPN Sessions
  - name: Virtual machines
  - name: Virtual machine backups
  - name: Virtual machine restores
paths:
  /virtual_machines/{virtual_machine_id}/network_attachments:
    post:
      tags:
        - Virtual machines
      summary: Attach a network to a VM
      description: >
        Attaches a virtual network (VLAN) to a Virtual Machine. Work runs
        asynchronously and returns 202 Accepted.
      operationId: create-virtual-machine-network-attachment
      parameters:
        - name: virtual_machine_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/virtual_machine_network_attachment_create_payload
          application/vnd.api+json:
            schema:
              $ref: >-
                #/components/schemas/virtual_machine_network_attachment_create_payload
      responses:
        '202':
          description: Accepted
          content:
            application/vnd.api+json:
              schema:
                type: object
                properties:
                  meta:
                    type: object
                    properties:
                      status:
                        type: string
                        example: accepted
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '422':
          description: Unprocessable Entity
      security:
        - Bearer: []
      x-codeSamples:
        - lang: go
          label: Go (SDK)
          source: "package main\n\nimport(\n\t\"context\"\n\t\"os\"\n\tlatitudeshgosdk \"github.com/latitudesh/latitudesh-go-sdk\"\n\t\"github.com/latitudesh/latitudesh-go-sdk/models/components\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := latitudeshgosdk.New(\n        latitudeshgosdk.WithSecurity(os.Getenv(\"LATITUDESH_BEARER\")),\n    )\n\n    res, err := s.VirtualMachines.CreateVirtualMachineNetworkAttachment(ctx, \"<id>\", components.VirtualMachineNetworkAttachmentCreatePayload{\n        Data: components.VirtualMachineNetworkAttachmentCreatePayloadData{\n            Type: components.VirtualMachineNetworkAttachmentCreatePayloadTypeVirtualMachineNetworkAttachments,\n            Attributes: components.VirtualMachineNetworkAttachmentCreatePayloadAttributes{\n                VirtualNetworkID: \"<id>\",\n            },\n        },\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.Object != nil {\n        // handle response\n    }\n}"
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Latitudesh } from "latitudesh-typescript-sdk";

            const latitudesh = new Latitudesh({
              bearer: process.env["LATITUDESH_BEARER"] ?? "",
            });

            async function run() {
              const result = await latitudesh.virtualMachines.createVirtualMachineNetworkAttachment({
                virtualMachineId: "<id>",
                virtualMachineNetworkAttachmentCreatePayload: {
                  data: {
                    type: "virtual_machine_network_attachments",
                    attributes: {
                      virtualNetworkId: "<id>",
                    },
                  },
                },
              });

              console.log(result);
            }

            run();
        - lang: python
          label: Python (SDK)
          source: |-
            import latitudesh_python_sdk
            from latitudesh_python_sdk import Latitudesh
            import os


            with Latitudesh(
                bearer=os.getenv("LATITUDESH_BEARER", ""),
            ) as latitudesh:

                res = latitudesh.virtual_machines.create_virtual_machine_network_attachment(virtual_machine_id="<id>", data={
                    "type": latitudesh_python_sdk.VirtualMachineNetworkAttachmentCreatePayloadType.VIRTUAL_MACHINE_NETWORK_ATTACHMENTS,
                    "attributes": {
                        "virtual_network_id": "<id>",
                    },
                })

                # Handle response
                print(res)
components:
  schemas:
    virtual_machine_network_attachment_create_payload:
      type: object
      properties:
        data:
          type: object
          properties:
            type:
              type: string
              enum:
                - virtual_machine_network_attachments
            attributes:
              type: object
              properties:
                virtual_network_id:
                  type: string
                  description: VLAN id_hash to attach (e.g. vlan_abc123).
              required:
                - virtual_network_id
          required:
            - type
            - attributes
      required:
        - data
  securitySchemes:
    Bearer:
      type: apiKey
      name: Authorization
      in: header

````