<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Admin API Sync User Directory not found in APIs</title>
    <link>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885361#M688</link>
    <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;for &lt;CODE&gt;DIRECTORY NOT FOUND&lt;/CODE&gt; I’d suggest double-checking the &lt;CODE&gt;directory_key&lt;/CODE&gt; value in your &lt;CODE&gt;apiEndpoint&lt;/CODE&gt;. If it was an authentication issue the response would not tell you the directory you specified wasn’t found, it would return a 401 like “Invalid signature in request credentials”.&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 29 Apr 2022 17:39:49 GMT</pubDate>
    <dc:creator>DuoKristina</dc:creator>
    <dc:date>2022-04-29T17:39:49Z</dc:date>
    <item>
      <title>Admin API Sync User Directory not found</title>
      <link>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885360#M687</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;I am using a PowerShell script to attempt to sync a user to a directory. I am getting back a&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;{"code": 40401, "message": "Resource not found", "message_detail": "Directory not found", "stat": "FAIL"}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Generally when I modify the script I’m getting an “code”: 40401, “message”: “Resource not found”&lt;/P&gt;
&lt;P&gt;This makes me believe its an Auth issue still&lt;/P&gt;
&lt;P&gt;I Am able to successfully get /auth/v2/check to work however&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;function New-DuoRequest(){
    param(
        [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            $apiHost,
        
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            [ValidateNotNull()]
            $apiEndpoint,
        
        [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            $apiKey,
        
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            [ValidateNotNull()]
            $apiSecret,
        
        [Parameter(Mandatory=$false,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            [ValidateNotNull()]
            $requestMethod = 'GET',
        
        [Parameter(Mandatory=$false,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            [ValidateNotNull()]
            [System.Collections.Hashtable]$requestParams
    )
    $date = (Get-Date).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss -0000")
    $formattedParams = ($requestParams.Keys | Sort-Object | ForEach-Object {$_ + "=" + [uri]::EscapeDataString($requestParams.$_)}) -join "&amp;amp;"
    
    #DUO Params formatted and stored as bytes with StringAPIParams
    $requestToSign = (@(
        $Date.Trim(),
        $requestMethod.ToUpper().Trim(),
        $apiHost.ToLower().Trim(),
        $apiEndpoint.Trim(),
        $formattedParams
    ).trim() -join "`n").ToCharArray().ToByte([System.IFormatProvider]$UTF8)
 
    $hmacsha1 = [System.Security.Cryptography.HMACSHA1]::new($apiSecret.ToCharArray().ToByte([System.IFormatProvider]$UTF8))
    $hmacsha1.ComputeHash($requestToSign) | Out-Null
    $authSignature = [System.BitConverter]::ToString($hmacsha1.Hash).Replace("-", "").ToLower()

    $authHeader = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(('{0}:{1}' -f $apiKey, $authSignature)))

    $httpRequest = @{
        URI         = ('https://{0}{1}' -f $apiHost, $apiEndpoint)
        Headers     = @{
            "X-Duo-Date"    = $Date
            "Authorization" = "Basic $authHeader"
        }
        Body = $requestParams
        Method      = $requestMethod
        ContentType = 'application/x-www-form-urlencoded'
    }
    
    $httpRequest
}

# Calling the function

$values = @{
    
    ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■'
    apiEndpoint     = '/admin/v1/users/directorysync/DIRECOTRYKEY/syncuser'
    requestMethod   = 'POST'
    requestParams   = @{username="JDOE"}
    apiSecret       = 'SECRETKEY'
    apiKey          = 'IKEY'
}
$contructWebRequest = New-DuoRequest @values

# Send the request
$wr = Invoke-WebRequest @contructWebRequest
$wr
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Apr 2022 14:20:17 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885360#M687</guid>
      <dc:creator>Keonip</dc:creator>
      <dc:date>2022-04-27T14:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Admin API Sync User Directory not found</title>
      <link>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885361#M688</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;for &lt;CODE&gt;DIRECTORY NOT FOUND&lt;/CODE&gt; I’d suggest double-checking the &lt;CODE&gt;directory_key&lt;/CODE&gt; value in your &lt;CODE&gt;apiEndpoint&lt;/CODE&gt;. If it was an authentication issue the response would not tell you the directory you specified wasn’t found, it would return a 401 like “Invalid signature in request credentials”.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 29 Apr 2022 17:39:49 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885361#M688</guid>
      <dc:creator>DuoKristina</dc:creator>
      <dc:date>2022-04-29T17:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Admin API Sync User Directory not found</title>
      <link>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885362#M689</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;I have 100% checked the directory key and even attempted multiple directories&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 May 2022 14:10:11 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885362#M689</guid>
      <dc:creator>Keonip</dc:creator>
      <dc:date>2022-05-02T14:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Admin API Sync User Directory not found</title>
      <link>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885363#M690</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;I copied the PowerShell example you have here to my test Windows VM, replaced some of the &lt;CODE&gt;$values&lt;/CODE&gt; info with those specific to my API host (the censored ■■■■ text), Admin API integration key and secret key, and my directory key and the user to sync, and it worked.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;PS C:\users\kristina\documents&amp;gt; $values = @{
&amp;gt;&amp;gt;
&amp;gt;&amp;gt;     ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■'
&amp;gt;&amp;gt;     apiEndpoint     = '/admin/v1/users/directorysync/DZkey/syncuser'
&amp;gt;&amp;gt;     requestMethod   = 'POST'
&amp;gt;&amp;gt;     requestParams   = @{username="duoprem.testuser@domain"}
&amp;gt;&amp;gt;     apiSecret       = 'skey'
&amp;gt;&amp;gt;     apiKey          = 'ikey'
&amp;gt;&amp;gt; }
PS C:\users\kristina\documents&amp;gt; echo $values

Name                           Value
----                           -----
apiEndpoint                    /admin/v1/users/directorysync/DZkey/syncuser
requestParams                  {username}
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
requestMethod                  POST
apiSecret                      skey
apiKey                         ikey


PS C:\users\kristina\documents&amp;gt; $contructWebRequest = New-DuoRequest @values
PS C:\users\kristina\documents&amp;gt; $wr = Invoke-WebRequest @contructWebRequest
PS C:\users\kristina\documents&amp;gt; $wr


StatusCode        : 200
StatusDescription : OK
Content           : {"response": {"message": "User duoprem.testuser@domain synced successfully.", "user": {"alias1": null, "alias2": null,
                    "alias3": null, "alias4": null, "aliases": {}, "created": 158...
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Pragma: no-cache
                    Strict-Transport-Security: max-age=31536000
                    Content-Security-Policy: default-src 'self'; frame-src 'self' ; img-src 'self'  ; connect-src 's...
Forms             : {}
Headers           : {[Connection, keep-alive], [Pragma, no-cache], [Strict-Transport-Security, max-age=31536000], [Content-Security-Policy, default-src 'self';
                    frame-src 'self' ; img-src 'self'  ; connect-src 'self']...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 899
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 May 2022 17:55:16 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/admin-api-sync-user-directory-not-found/m-p/4885363#M690</guid>
      <dc:creator>DuoKristina</dc:creator>
      <dc:date>2022-05-02T17:55:16Z</dc:date>
    </item>
  </channel>
</rss>

