---
title: "[beta] Create a Function."
method: POST
path: "/functions"
tags: ["Beta APIs"]
---

# \[beta\] Create a Function.

`POST /functions`

## Request

- Base URL: `https://api.samsara.com`
- URL: `https://api.samsara.com/functions`
- Auth: HTTP bearer

Create a new Function with the given name, description, and configuration. The response includes a URL (`uploadPutUrl`) for uploading the function's code package. After uploading, call `POST /functions/{name}/deploy` to make the function runnable.

 <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

To use this endpoint, select **Write Functions** under the Functions category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>
 

 **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

## Request body

- FunctionsCreateFunctionRequestBody: Request body for creating a Function.
  - `config` CreateFunctionRequestConfigRequestBody, required: Configuration for the new Function.
    - `handler` string, required: The handler entrypoint for the function code (e.g. 'index.handler').
    - `isScheduleEnabled` boolean: Whether the run schedule is enabled.
    - `params` object: Default parameter values for the function.
    - `schedule` FunctionScheduleRequestBody: Schedule configuration for a Function.
      - `entries` FunctionScheduleEntryRequestBody[], required: Schedule entries defining when the function runs.
        - `daysOfWeek` boolean[], required: Days of the week this entry applies to (7 elements, index 0 = Sunday).
        - `timeSinceMidnightMs` integer, required: Time since midnight in milliseconds when the function runs.
      - `timezone` string, required: IANA timezone name for the schedule.
    - `secrets` object: Secrets available to the function at runtime.
  - `description` string: A description of the Function.
  - `name` string, required: Unique name for the Function.

## Response `200`

OK response.

- FunctionsCreateFunctionResponseBody
  - `data` CreateFunctionDetailResponseBody, required: Details of a newly created Function, including a URL for uploading the code package. After uploading, call the deploy endpoint to make the function runnable.
    - `codePackage` FunctionCodePackageResponseBody, required: Code package status for the Function.
      - `downloadGetUrl` string: A presigned GET URL for downloading the function's current code package. Present only when code has been uploaded.
      - `status` 'unknown' | 'pendingUpload' | 'uploaded' | 'deployed', required: Status of the code package. Valid values: `unknown`, `pendingUpload`, `uploaded`, `deployed`
    - `config` FunctionConfigResponseBody, required: Configuration of the Function.
      - `handler` string, required: The handler entrypoint for the function code.
      - `isScheduleEnabled` boolean, required: Whether the run schedule is enabled.
      - `params` object, required: Default parameters for the function.
      - `schedule` FunctionScheduleResponseBody: Schedule configuration for a Function.
        - `entries` FunctionScheduleEntryResponseBody[], required: Schedule entries defining when the function runs.
          - `daysOfWeek` boolean[], required: Days of the week this entry applies to (7 elements, index 0 = Sunday).
          - `timeSinceMidnightMs` integer, required: Time since midnight in milliseconds when the function runs.
        - `timezone` string, required: IANA timezone name for the schedule.
      - `secrets` object, required: Secret names available to the function. Values are always empty.
    - `createdAtTime` string, date-time, required: RFC 3339 timestamp when the Function was created.
    - `description` string: Description of the Function.
    - `effects` FunctionEffectsResponseBody, required: Computed effects of the Function configuration.
      - `nextScheduledAtTime` string, date-time: RFC 3339 timestamp of the next scheduled run. Omitted if no schedule is set.
    - `lastUpdateTimestampMs` integer, required: Epoch milliseconds of the last update. Use this value for optimistic locking in PATCH requests.
    - `name` string, required: Name of the Function.
    - `updatedAtTime` string, date-time, required: RFC 3339 timestamp when the Function was last updated.
    - `uploadPutUrl` string, required: A presigned PUT URL for uploading the function's code package. Valid for a limited time. After uploading, call `POST /functions/{name}/deploy` to make the function runnable.

## Other responses

- `401`: Unauthorized response.
- `404`: Not Found response.
- `405`: Method Not Allowed response.
- `413`: Content Too Large response.
- `429`: Too Many Requests response.
- `500`: Internal Server Error response.
- `501`: Not Implemented response.
- `502`: Bad Gateway response.
- `503`: Service Unavailable response.
- `504`: Gateway Timeout response.
- `default`: Bad Request response.

---

[API](https://skmtc.dev/samsara/apis/samsara-api.md) - [All operations](https://skmtc.dev/samsara/apis/samsara-api/llms.txt) - [OpenAPI document](https://skmtc.dev/samsara/apis/samsara-api/revisions/a9e35d4999be?raw)
