# Connecting to an Apple service with API key

[Connecting to an Apple service](/bitrise-platform/integrations/apple-services-connection/about-connecting-to-apple-services) (such as the App Store Connect or the Apple Developer Portal) with the API key requires generating an API key, adding the authentication data on Bitrise, and assigning the key to the app.

The API key authentication is the recommended way when connecting Bitrise to Apple Services. You can have 50 API keys added to the **Apple Services connection** page but your app can use only one.

:::important[No Step input modifications needed]

With this method, all Step inputs related to authenticating with an Apple API key are automatically populated once the connection is set up. You don't have to manually modify those Step input fields at all.

:::

## Adding API key authentication data on Bitrise

You can add API key authentication data on the **Workspace settings** page. You can add multiple API keys here. You can select between different API keys for each project, using them either for Bitrise CI or Bitrise Release Management.

1. On [App Store Connect](https://appstoreconnect.apple.com/login), [generate a new API key with Admin access](https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api) under **Users and Access**.

   You will need the name of the key, the key ID and the issuer ID on Bitrise.

   :::warning[Requirements]

   - The API key must be [a team API key](https://developer.apple.com/documentation/appstoreconnectapi/creating-api-keys-for-app-store-connect-api#Generate-a-Team-Key-and-Assign-It-a-Role). An individual API key won't work.

     ![apple-app-store-connect.png](/img/_paligo/uuid-b104fac1-d553-69d3-ebcb-b8260e8a3595.png)
   - The API key must be set up with the **Admin** role on the App Store. Your builds will fail otherwise.
   - On Bitrise, you must be a workspace **Owner** or **Manager** to be able to add the API key data. For more information, check out [Workspace-level roles](/bitrise-platform/workspaces/collaboration-and-permissions-in-workspaces/roles-and-permissions-in-workspaces#workspace-level-roles).

   :::
1. On Bitrise, select your workspace from the dropdown menu and go to **Settings**.
1. On the left, select **Integrations**.
1. Select **App Store Connect**.
1. Click **Add API key**.

   :::note[Required roles]

   If you can't see the button, it's because you only have a **Viewer** or **Contributor** role in the workspace. You need to be either an **Owner** or a **Manager**.

   For more information, check out [Workspace-level roles](/bitrise-platform/workspaces/collaboration-and-permissions-in-workspaces/roles-and-permissions-in-workspaces#workspace-level-roles).

   :::

   ![api-key-app-store.png](/img/_paligo/uuid-1bbd8347-eb11-4439-9ece-315d004d74fe.png)
1. Fill out all required fields:

   - **Name**: Your generated API key's name.
   - **Issuer ID**: To get your issuer ID, log in to App Store Connect and select **Users and Access**, then select the **API Keys** tab.The issuer ID appears near the top of the page. To copy the issuer ID, click **Copy** next to the ID.
   - **Key ID**: When you successfully generate a new API key, App Store Connect shows you the key ID.

   ![api-key-dialog.png](/img/_paligo/uuid-22e6048e-7f47-9480-fea3-958eb9a0348b.png)
1. If your API key is an Apple Enterprise API key, check **Use for Enterprise Program API**.

   ![api-key-enterprise.png](/img/_paligo/uuid-7dc1ff71-7abf-8c37-8117-a2f7abb13861.png)
1. Upload the `.p8` file: either drag and drop it to the upload field, or click it and select the file from your computer.
1. Click **Add API key**.

Once done, you can now assign this API key to any app that you have access to on this account. From then, the app will use that API connection to access App Store Connect.

## Assigning API key authentication to your project

To use API key authentication for Apple services for your project, you must:

- [Add an API key on Bitrise](/bitrise-platform/integrations/apple-services-connection/connecting-to-an-apple-service-with-api-key#adding-api-key-authentication-data-on-bitrise): You can add multiple API keys to the same account. If your API key is an Apple Enterprise API key, check **Use for Enterprise Program API** when adding it.
- Assign an API key to your project: Each project can only have one API key assigned to it.

To assign the API key to the project:

1. 1. Open your project on Bitrise with a user that has the **Admin** [role on the project](/bitrise-platform/projects/roles-and-permissions-for-bitrise-ci), or a [custom role](/bitrise-platform/workspaces/collaboration-and-permissions-in-workspaces/custom-roles/custom-roles-overview) with the **Edit workflows** permission.
1. On the main page of the project, click on the **Project settings** button.
1. On the left, select **Integrations**.
1. Select the **Stores** tab.
1. Find the **App Store Connect** section.

   ![add-api-key-apple.png](/img/_paligo/uuid-95e5fcc6-46bd-1efe-69a0-538ef9c8c8cb.png)
1. Find the **API key authentication (recommended)** option.
1. Click **Add API key**.

   :::note[Multiple projects with the same API key]

   With the **Add API key** button, you can add a new App Store Connect API key to your Bitrise account. Other projects you have access to can use this API key, too.

   :::
1. Select the API key you want to use for this project.

The Step is now able to connect to the App Store Connect or the Apple Developer Portal during your build.

## API key authentication for Apple Enterprise users

Apple accounts that are part of the Enterprise developer program can also use API key-based authentication.

If your Enterprise account still uses Apple ID authentication, we strongly recommend switching to API key authentication because:

- It's more reliable and secure.
- It doesn't have to be re-authorized every 30 days.
- The Apple ID authentication method will be deprecated at some point.

To change your authentication method:

1. If you haven't already, [add an API key on Bitrise](/bitrise-platform/integrations/apple-services-connection/connecting-to-an-apple-service-with-api-key#adding-api-key-authentication-data-on-bitrise), making sure to check **Use for Enterprise Program API**.
1. [Assign the API key](/bitrise-platform/integrations/apple-services-connection/connecting-to-an-apple-service-with-api-key#assigning-api-key-authentication-to-your-project) to your project(s) on Bitrise.

   :::caution[Keep the Apple ID connection]

   We strongly recommend not to remove your Apple ID connection. If there are any issues with the API key connection, you can safely roll back to Apple ID-based authentication.

   :::
1. Adjust all Step inputs that use Apple ID authentication to access Apple services. The following Steps are affected:

   - **Xcode Archive & Export for iOS**: version 5.3.0 and above. Set the `automatic_code_signing` input to `api-key`.
   - **Xcode Build for Testing**: version 3.1.0 and above. Set the `automatic_code_signing` input to `api-key`.
   - **Manage iOS Code Signing**: version 2.1.0 and above. Set the `apple_service_connection` input to `api-key`.
   - **Export iOS and tvOS Xcode archive**: version 4.6.0 and above. Set the `automatic_code_signing` input to `api-key`.

### Multiple API keys for the same project

You can only set up one API connection for each project on the Bitrise website. That means the project can handle the code signing files of only one Apple developer team: API keys only give authorization to a single developer team.

![api-key-chart.png](/img/_paligo/uuid-ea47d90b-0ff0-7cd5-2f80-4013e10f7fb3.png)

If your Bitrise project needs to handle the code signing of multiple developer teams, you can pass additional API keys as Step inputs. Doing so overrides the Bitrise-managed API connection. The available inputs differ by Step:

| Step | Inputs |
| --- | --- |
| Xcode Archive & Export for iOSXcode Build for TestingManage iOS Code SigningExport iOS and tvOS Xcode archive | `api_key_path`: A local file path or download URL for the API key.`api_key_id`: The key ID from App Store Connect.`api_key_issuer_id`: The issuer ID from App Store Connect.`api_key_enterprise_account`: `yes` or `no`, whether the key belongs to an Apple Enterprise Program account. |
| fastlaneDeploy to App Store Connect with Deliver | `api_key_path`: A local file path or download URL for the API key. Embed the key ID in the file name — there's no separate key ID input.`api_issuer`: The issuer ID from App Store Connect. |

:::note[Inputs on the GUI]

On the graphical UI of the Bitrise Workflow Editor, you can find these inputs under the **App Store Connect connection override** input group on the **Configuration** tab of each Step that can access Apple services.

:::
