You could use api Authorizedresources - Authorize Project Resources to authorize the resource:
PATCH https://dev.azure.com/{organization}/{project}/_apis/build/authorizedresources?api-version=6.0-preview.1
Body:
[{"authorized":true,"id":"$queueID","name":"$queueName","type":"queue"}]
There are a few things here:
The “Grant access permissions to all pipelines” setting is per pool per project. But this is toggled via the linked UI or set at creation
time in the project settings “add pool” UI.
Pools, at the Organization (or Collection) level, have two settings on them which can be seen in the “Add New Pool” dialog at the
Organization level. “Auto-provision this agent pool in all projects”
will go ahead and add the pool to all existing projects, as well as
when a new project is added in the future. “Grant access permission to
all pipelines” sets the default state of the per project level setting
above when adding this pool to projects.
The “Default” pool comes preset with “Auto-provision” set to true, and
“Grant access…” set to false. So when creating a new project, it will
have the “Default” pool available, and in the “Default” pool settings
UI for that project “Grant access…” will be set to false until a user
updates it.
To modify the “Grant access…” setting seen in the Project Settings
Agent Pool UI linked above, you can use the API above, or go to
Project settings -- Agent Pools, and toggled the permission as the
screenshot below shows:
If you want to modify the Organization setting’s “Default” pool’s
default value for “Grant access…” when adding the pool to new
projects, you can do it with the following REST API:
PATCH https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}
Headers:
Accept: /;api-version=6.0-preview.1;excludeUrls=true
Content-Type: application/json
Body:
{“id”:“1”,“Properties”:{“System.AutoAuthorize”: “true”}}
Refer to case: https://developercommunity.visualstudio.com/content/problem/887182/new-pipeline-permissions-feature-causing-builds-to.html