You can Override the YAML the PR trigger and Enable pull request validation of a GitHub repo with this API.
Per the request body of above request, you may first get the latest pipeline definition revision from the response of the following API first.
GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.2-preview.7
We can then copy the response as the body of the Definition-Update-API request and simply update the triggerS section. Here is a sample json contents of the modified trigger section for your reference. In the second object for "triggerType": "pullRequest", I removed "settingsSourceType": 2, and updated "branchFilters": ["+refs/heads/main"].
PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.2-preview.7
{
…
"triggers": [
{
"branchFilters": "",
"pathFilters": "",
"settingsSourceType": 2,
"batchChanges": false,
"maxConcurrentBuildsPerBranch": 1,
"triggerType": "continuousIntegration"
},
{
"branchFilters": [
"+refs/heads/main"
],
"forks": "@{enabled=False; allowSecrets=False; allowFullAccessToken=False}",
"pathFilters": "",
"requireCommentsForNonTeamMembersOnly": false,
"requireCommentsForNonTeamMemberAndNonContributors": false,
"isCommentRequiredForPullRequest": false,
"pipelineTriggerSettings": "@{forkProtectionEnabled=True; buildsEnabledForForks=True; enforceJobAuthScopeForForks=False; enforceNoAccessToSecretsFromForks=False; isCommentRequiredForPullRequest=False; requireCommentsForNonTeamMembersOnly=False; requireCommentsForNonTeamMemberAndNonContributors=False}",
"triggerType": "pullRequest"
}
],
…
}