# Self-hosted API Setup

{% hint style="warning" %}
This step is optional for anyone who deployed after v7.1.x. If you are coming from v7.1.x or earlier, your Function App identity needs the "Contributor" role assigned to itself. You can do this manually, or with the PowerShell Role Assignment script. Both options are described below.
{% endhint %}

#### Assign the “Contributor” Role to the Function App

If you're self-hosting and running your own Azure Function App, you'll need to grant it proper access:

{% stepper %}
{% step %}
Go to [Azure Portal](https://portal.azure.com).
{% endstep %}

{% step %}
Open the resource group hosting CIPP.
{% endstep %}

{% step %}
Select the **Function App** (not an offloaded app).
{% endstep %}

{% step %}
Navigate to **Access control (IAM)** > **+ Add** > **Add role assignment**.
{% endstep %}

{% step %}
Click on Privileged administrator roles.
{% endstep %}

{% step %}
Choose:

* **Role:** Contributor
* **Assign access to:** User, group, or service principal
* **Select:** The CIPP Function App identity

{% hint style="info" %}
The **Contributor** role should allow the identity to create and manage all types of Azure resources but does not allow them to grant access to others.

In the **Select** field and type `cipp`. As you begin typing, the list of options will narrow, and you should see the Managed Identity for your Function App.
{% endhint %}
{% endstep %}

{% step %}
Click **Save.**
{% endstep %}
{% endstepper %}

***

#### PowerShell Role Assignment (Alternative)

You can also use Azure Cloud Shell:

```powershell
$RGName = Read-Host -Prompt "Resource Group Name"
Connect-AzAccount
$Functions = Get-AzResource -ResourceGroupName $RGName -ResourceType 'Microsoft.Web/sites' | Where-Object { $_.Name -match 'cipp' -and $_.Name -notmatch '-' }
$FunctionApp = Get-AzWebApp -ResourceGroupName $Functions.ResourceGroupName -Name $Functions.Name
$Identity = $FunctionApp.Identity.PrincipalId
New-AzRoleAssignment -ObjectId $Identity -RoleDefinitionName 'Contributor' -Scope $FunctionApp.Id
```

{% embed url="<https://shell.azure.com/powershell>" fullWidth="false" %}
This script can be run in Azure Cloud Shell. Click the link to be taken to the Azure Portal.
{% endembed %}

***

{% hint style="success" %}
Once configured, head over to the [CIPP-API](/user-documentation/cipp/integrations/cipp-api.md) Integration page in your CIPP UI.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cipp.app/setup/maintaining-cipp/self-hosted-api-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
