Unable to use the Enterprise App Store Connect APIs from xcodebuild

With the recently introduced Enterprise API Program, this should allow us to interact with the developer portal via the API instead of needing an account signed into Xcode.

I followed the following steps to generate a key:

  1. Logged into App Store Connect.
  2. Navigated to Users and Access.
  3. Selected Integrations.
  4. Generated an API key with the Admin role.
  5. Saved the key, the key identifier, and the issuer identifier.

Now, when using xcodebuild with the -allowProvisioningUpdates switch, I added -authenticationKeyPath, -authenticationKeyID, and -authenticationKeyIssuerID with the correct values.

xcodebuild spits out the following error:

xcodebuild: error: Invalid authentication key credential specified (CryptoKit.CryptoKitASN1Error.invalidPEMDocument)

What am I doing wrong/what did I miss? The developer portal shows that the key was "used" by updating the last used date.

Answered by DTS Engineer in 802598022

What am I doing wrong

Nothing. These keys don't support enterprise accounts. If you would like Apple to consider adding this feature, please file your suggestion using Feedback Assistant, then post your Feedback number here.

Accepted Answer

What am I doing wrong

Nothing. These keys don't support enterprise accounts. If you would like Apple to consider adding this feature, please file your suggestion using Feedback Assistant, then post your Feedback number here.

Logged as FB15055171

Please generate a new Enterprise Program API key. Let us know here if the issue still persists.

Thanks - our team faced similar issue - and I can confirm for us it is now resolved with newly generated keys working as expected. API calls are succeeding.

Please pass on grateful thanks to the Enterprise API team for making these APIs available - a welcome bonus.

I went ahead and generated a new key, but I am still unable to get this to work.

The original error is gone, but now I receive a 401 error from the developer portal using Xcode 16 RC (16A242):

env NSUnbufferedIO=YES xcodebuild clean archive -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -archivePath results/artifacts/App.xcarchive -destination generic/platform=iOS -derivedDataPath build -allowProvisioningUpdates -authenticationKeyID **** -authenticationKeyIssuerID **** -authenticationKeyPath /Users/MyUser/MyKey.p8

GatherProvisioningInputs
2024-09-12 07:40:48.226 xcodebuild[41720:6825977]  DVTServices: Received response for 0119471B-B1ED-435F-B036-97D661247558 @ <https://appstoreconnect.apple.com/xcbuild/QH65B2/listTeams.action?clientId=XABBG36SBA>. Error = Error Domain=DVTPortalResponseErrorDomain Code=0 "Communication with Apple failed" UserInfo={NSLocalizedDescription=Communication with Apple failed, NSLocalizedRecoverySuggestion=A non-HTTP 200 response was received (401) for URL https://appstoreconnect.apple.com/xcbuild/QH65B2/listTeams.action?clientId=XABBG36SBA}

2024-09-12 07:40:48.393 xcodebuild[41720:6825977]  DVTServices: Received response for 7A81B4FA-E41E-47BB-9C7A-D641D09BB9C2 @ <https://appstoreconnect.apple.com/xcbuild/QH65B2/listTeams.action?clientId=XABBG36SBA>. Error = Error Domain=DVTPortalResponseErrorDomain Code=0 "Communication with Apple failed" UserInfo={NSLocalizedDescription=Communication with Apple failed, NSLocalizedRecoverySuggestion=A non-HTTP 200 response was received (401) for URL https://appstoreconnect.apple.com/xcbuild/QH65B2/listTeams.action?clientId=XABBG36SBA}

@madsolar8582

xcodebuild clean archive -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -archivePath results/artifacts/App.xcarchive -destination generic/platform=iOS -derivedDataPath build -allowProvisioningUpdates -authenticationKeyID **** -authenticationKeyIssuerID **** -authenticationKeyPath /Users/MyUser/MyKey.p8

Running xcodebuild with the authentication API keys only supports exporting archives. This workflow doesn't support building and archiving.

To upload your binary, first archive your binary, create a plist file that configures archive exporting, gather your Enterprise Authentication API keys from the portal, then run the following command in Terminal:

xcodebuild -exportArchive 
                   -archivePath <xcarchivepath>
                   -exportPath <destinationpath> 
                   -exportOptionsPlist <path> 
                  -allowProvisioningUpdates
                   -authenticationKeyPath <keypath> 
                   -authenticationKeyID <keyidentifier> 
                  -authenticationKeyIssuerID <keyissueridentifier>

The -exportArchive option specifies that xcodebuild should distribute the archive specified by -archivePath using the options specified by -exportOptionsPlist. xcodebuild -help can print the full set of available inputs to -exportOptionsPlist (set the destination string to upload in the plist file). The exported product will be placed at the path specified by -exportPath.

To clean then archive your MyApp scheme in your MyApp workspace using itsRelease configuration, run the following command in Terminal:

xcodebuild clean archive -workspace MyApp.xcworkspace -scheme MyApp -configuration Release

This is quite unfortunate.

Today, we pass in the allowProvisioningUpdates flag on test, archive, and exportArchive to ensure that 1) the development profile is up to date and 2) the distribution profile is up to date. This does not error when using an account signed into Xcode. The reason we are attempting to use the API is that this is the suggested workaround from FB14060904.

What I’m gathering is that the API is not 1:1 with the operations Xcode can do when an account is signed in. If that is the case, I would expect some more descriptive error messages and clarifications in the man page.

Unable to use the Enterprise App Store Connect APIs from xcodebuild
 
 
Q