Share via

CSOM code is not working after adding custom domain to MS365 Tenant

KINTALI SANTOSH KUMAR 1 Reputation point
2022-07-25T06:23:35.903+00:00

Hi,

Recently, my organisation added custom domain and user upn also changed according to it. Now, CSOM code is giving error as "The Application ID (AppID) For Which The Service Ticket Is Requested Does Not Exist On The System".

SCRIPT BELOW

Add-Type -Path "D:\CSOM Code Test\Microsoft.SharePoint.Client.dll"
Add-Type -Path "D:\CSOM Code Test\Microsoft.SharePoint.Client.Runtime.dll"

$siteURL = https://XXXX.sharepoint.com/sites/MF

$userId = SVC_SPO.Mig_Acc1@X****

$pwd = Read-Host -Prompt "Enter Password" -AsSecureString

$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)

$ctx.credentials = $creds

try{

$lists = $ctx.web.Lists   

$list = $lists.GetByTitle("VMs")   

$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())   

$ctx.load($listItems)   

    

$ctx.executeQuery()   

foreach($listItem in $listItems)   

{   

    Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]   

}   

}

catch{

write-host "$($_.Exception.Message)" -foregroundcolor red   

}

Error screenshot:

224234-microsoftteams-image-4.png

Microsoft 365 and Office | SharePoint | For business | Windows

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,261 Reputation points
    2022-07-26T09:21:48.4+00:00

    Hi @KINTALI SANTOSH KUMAR ,

    According to my research and testing ,please try to do a troubleshooting, please check if you have Full Control on Tenant .

    You can refer to this document: The Application ID (AppID) For Which The Service Ticket Is Requested Does Not Exist On The System

    As a workaround , I suggest you can use the following code to connect to the SharePoint Online :

    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
      
    $SiteUrl = "https://xxxx.sharepoint.com/sites/xxx"  
        
    #Get Credentials to connect to SharePoint Online site  
    $Cred = Get-Credential  
          
    #Set up the context  
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)  
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
      
      
      
    try{  
      
     $lists = $ctx.web.Lists   
     $list = $lists.GetByTitle("test")   
     $listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())   
     $ctx.load($listItems)   
            
     $ctx.executeQuery()   
     foreach($listItem in $listItems)   
     {   
         Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]   
     }   
      
    }  
      
    catch{  
      
     write-host "$($_.Exception.Message)" -foregroundcolor red   
      
    }  
    

    My test result:
    224822-image.png

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.