> ## 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.

# Create firewall

> Create a firewall



## OpenAPI

````yaml https://spec.speakeasy.com/latitude/latitude/latitude-sh-api-with-code-samples post /firewalls
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: Storage
  - name: Tags
  - name: Teams
  - name: Team members
  - name: Traffic
  - name: User data
  - name: User profile
  - name: VPN Sessions
  - name: Virtual machines
paths:
  /firewalls:
    post:
      tags:
        - Firewalls
      summary: Create firewall
      description: Create a firewall
      operationId: create-firewall
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - firewalls
                    attributes:
                      type: object
                      properties:
                        name:
                          type: string
                        project:
                          type: string
                        rules:
                          type: array
                          items:
                            type: object
                            properties:
                              from:
                                type: string
                                description: >-
                                  Source IP address, IP range in CIDR notation,
                                  or 'ANY' (e.g., "192.168.1.1",
                                  "192.168.1.0/24", "ANY")
                              to:
                                type: string
                                description: >-
                                  Destination IP address, IP range in CIDR
                                  notation, or 'ANY' (e.g., "192.168.1.1",
                                  "192.168.1.0/24", "ANY")
                              protocol:
                                type: string
                                enum:
                                  - TCP
                                  - UDP
                              port:
                                type: string
                                description: Port number or range (e.g., "80", "80-443")
                              description:
                                type: string
                                nullable: true
                                description: >-
                                  Optional description explaining the purpose of
                                  this rule
                      required:
                        - name
                        - project
                  required:
                    - type
              required:
                - data
            examples:
              Created:
                summary: Created
                value:
                  data:
                    type: firewalls
                    attributes:
                      name: my-firewall
                      project: heavy-duty-copper-watch
                      rules:
                        - from: 192.168.42.73
                          to: 192.168.43.51
                          port: 80
                          protocol: TCP
                          description: Allow HTTP traffic
                        - from: 192.168.1.16
                          to: 192.168.1.30
                          port: '80'
                          protocol: TCP
                        - from: 192.168.1.10
                          to: 192.168.1.20
                          port: 3000-4000
                          protocol: UDP
                          description: Application ports
          application/vnd.api+json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - firewalls
                    attributes:
                      type: object
                      properties:
                        name:
                          type: string
                        project:
                          type: string
                        rules:
                          type: array
                          items:
                            type: object
                            properties:
                              from:
                                type: string
                                description: >-
                                  Source IP address, IP range in CIDR notation,
                                  or 'ANY' (e.g., "192.168.1.1",
                                  "192.168.1.0/24", "ANY")
                              to:
                                type: string
                                description: >-
                                  Destination IP address, IP range in CIDR
                                  notation, or 'ANY' (e.g., "192.168.1.1",
                                  "192.168.1.0/24", "ANY")
                              protocol:
                                type: string
                                enum:
                                  - TCP
                                  - UDP
                              port:
                                type: string
                                description: Port number or range (e.g., "80", "80-443")
                              description:
                                type: string
                                nullable: true
                                description: >-
                                  Optional description explaining the purpose of
                                  this rule
                      required:
                        - name
                        - project
                  required:
                    - type
              required:
                - data
            examples:
              Created:
                summary: Created
                value:
                  data:
                    type: firewalls
                    attributes:
                      name: my-firewall
                      project: heavy-duty-copper-watch
                      rules:
                        - from: 192.168.42.73
                          to: 192.168.43.51
                          port: 80
                          protocol: TCP
                          description: Allow HTTP traffic
                        - from: 192.168.1.16
                          to: 192.168.1.30
                          port: '80'
                          protocol: TCP
                        - from: 192.168.1.10
                          to: 192.168.1.20
                          port: 3000-4000
                          protocol: UDP
                          description: Application ports
        required: true
      responses:
        '201':
          description: Created
          content:
            application/vnd.api+json:
              examples:
                Created:
                  value:
                    data:
                      id: fw_w5AEmq7XDBkWX
                      type: firewalls
                      attributes:
                        name: my-firewall
                        project:
                          id: proj_RLYV8DZ2D5QoE
                          name: Heavy Duty Copper Watch
                          slug: heavy-duty-copper-watch
                        rules:
                          - from: ANY
                            to: ANY
                            port: '22'
                            protocol: TCP
                            default: true
                          - from: 192.168.42.73
                            to: 192.168.43.51
                            port: '80'
                            protocol: TCP
                            default: false
                          - from: 192.168.1.16
                            to: 192.168.1.30
                            port: '80'
                            protocol: TCP
                            default: false
                          - from: 192.168.1.10
                            to: 192.168.1.20
                            port: 3000-4000
                            protocol: UDP
                            default: false
              schema:
                $ref: '#/components/schemas/firewall'
      security:
        - Bearer: []
      x-codeSamples:
        - 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.firewalls.create(data={
                    "type": latitudesh_python_sdk.CreateFirewallFirewallsType.FIREWALLS,
                    "attributes": {
                        "name": "my-firewall",
                        "project": "heavy-duty-copper-watch",
                        "rules": [
                            {
                                "from_": "192.168.42.73",
                                "to": "192.168.43.51",
                                "protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
                                "port": "80",
                                "description": "Allow HTTP traffic",
                            },
                            {
                                "from_": "192.168.1.16",
                                "to": "192.168.1.30",
                                "protocol": latitudesh_python_sdk.CreateFirewallProtocol.TCP,
                                "port": "80",
                            },
                            {
                                "from_": "192.168.1.10",
                                "to": "192.168.1.20",
                                "protocol": latitudesh_python_sdk.CreateFirewallProtocol.UDP,
                                "port": "3000-4000",
                                "description": "Application ports",
                            },
                        ],
                    },
                })

                # Handle response
                print(res)
        - 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/operations\"\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.Firewalls.Create(ctx, operations.CreateFirewallFirewallsRequestBody{\n        Data: operations.CreateFirewallData{\n            Type: operations.CreateFirewallTypeFirewalls,\n            Attributes: &operations.CreateFirewallAttributes{\n                Name: \"my-firewall\",\n                Project: \"heavy-duty-copper-watch\",\n                Rules: []operations.CreateFirewallRules{\n                    operations.CreateFirewallRules{\n                        From: latitudeshgosdk.Pointer(\"192.168.42.73\"),\n                        To: latitudeshgosdk.Pointer(\"192.168.43.51\"),\n                        Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),\n                        Port: latitudeshgosdk.Pointer(\"80\"),\n                        Description: latitudeshgosdk.Pointer(\"Allow HTTP traffic\"),\n                    },\n                    operations.CreateFirewallRules{\n                        From: latitudeshgosdk.Pointer(\"192.168.1.16\"),\n                        To: latitudeshgosdk.Pointer(\"192.168.1.30\"),\n                        Protocol: operations.CreateFirewallProtocolTCP.ToPointer(),\n                        Port: latitudeshgosdk.Pointer(\"80\"),\n                    },\n                    operations.CreateFirewallRules{\n                        From: latitudeshgosdk.Pointer(\"192.168.1.10\"),\n                        To: latitudeshgosdk.Pointer(\"192.168.1.20\"),\n                        Protocol: operations.CreateFirewallProtocolUDP.ToPointer(),\n                        Port: latitudeshgosdk.Pointer(\"3000-4000\"),\n                        Description: latitudeshgosdk.Pointer(\"Application ports\"),\n                    },\n                },\n            },\n        },\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.Firewall != 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.firewalls.create({
                data: {
                  type: "firewalls",
                  attributes: {
                    name: "my-firewall",
                    project: "heavy-duty-copper-watch",
                    rules: [
                      {
                        from: "192.168.42.73",
                        to: "192.168.43.51",
                        protocol: "TCP",
                        port: "80",
                        description: "Allow HTTP traffic",
                      },
                      {
                        from: "192.168.1.16",
                        to: "192.168.1.30",
                        protocol: "TCP",
                        port: "80",
                      },
                      {
                        from: "192.168.1.10",
                        to: "192.168.1.20",
                        protocol: "UDP",
                        port: "3000-4000",
                        description: "Application ports",
                      },
                    ],
                  },
                },
              });

              console.log(result);
            }

            run();
components:
  schemas:
    firewall:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/firewall_data'
        meta:
          type: object
    firewall_data:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - firewalls
        attributes:
          type: object
          properties:
            name:
              type: string
            rules:
              type: array
              items:
                type: object
                properties:
                  from:
                    type: string
                    description: >-
                      Source IP address, IP range in CIDR notation, or 'ANY'
                      (e.g., "192.168.1.1", "192.168.1.0/24", "ANY")
                  to:
                    type: string
                    description: >-
                      Destination IP address, IP range in CIDR notation, or
                      'ANY' (e.g., "192.168.1.1", "192.168.1.0/24", "ANY")
                  port:
                    type: string
                  protocol:
                    type: string
                  description:
                    type: string
                    nullable: true
                    description: Optional description explaining the purpose of this rule
            project:
              type: object
              properties:
                id:
                  type: string
                name:
                  type: string
                slug:
                  type: string
  securitySchemes:
    Bearer:
      type: apiKey
      name: Authorization
      in: header

````