Skip to main content
Mar 21, 2025 8:06 PM UTC
Question

Is it possible to create a new item in a vault using an Azure function app without Connect Server?

I need to know if creating a new item using rest api in an azure powershell function app is possible. Here is a snippet of what I've been trying:

# Get 1Password API token and vault ID from environment variables
$apiToken = $env:1PASSWORD_API_TOKEN
$vaultId = $env:1PASSWORD_VAULT_ID

# Set up the API URL
$apiUrl = "https://api.1password.com/v1/vaults/$vaultId/items"

# Prepare the request body with 'apikey' as the literal value
$body = @{
    title    = "APIM Credentials - $customer"
    category = "API_CREDENTIAL"
    fields   = @(
        @{ label = "username"; value = "apikey"; type = "STRING" },  # Use the literal 'apikey' as the value
        @{ label = "password"; value = $primaryKey; type = "CONCEALED" }
    )
} | ConvertTo-Json -Depth 10

# Set headers
$headers = @{
    "Authorization" = "Bearer $apiToken"
    "Content-Type"  = "application/json"
}

# Send request to create item
try {
    $response = Invoke-RestMethod -Uri $apiUrl -Method Post -Headers $headers -Body $body
    Write-Host "Created API key in 1Password: $($response.id)"
} catch {
    Write-Host "ERROR: Failed to create item in 1Password"
    Write-Host "Response: $($_.Exception.Message)"
    return
}

3 replies

phildmno
Mar 24, 2025 8:03 PM UTC

I think you'll need to use either the CLI or one of the SDKs to do this without Connect. Since it's Powershell, the CLI probably makes the most sense. 

tbutcherAuthor
Mar 24, 2025 8:07 PM UTC

Hi there, do you know if it's possible to use 1password cli within an Azure function app environment though? Thanks!

phildmno
Mar 24, 2025 8:13 PM UTC

It looks like you can https://learn.microsoft.com/en-us/azure/azure-functions/bring-dependency-to-functions?pivots=programming-language-python, (that example is python, but it shouldn't be that different in your preferred language)