OCS API using VBA

NC version: 24.0.3
Hosted on a BlueHost instance, PHP version 7.4

Hi, I’m trying to execute a get request for a list of all users in the NC instance.
The cURL command is executing 100%, but doing it in Excel VBA is simply not succeeding.
My code in VBA:

Sub VBA_XML_API()

'declare the xml object
Dim xml_obj As New MSXML2.XMLHTTP60

base_url = “https://nextcloud.mydomain.com
Endpoint = “/ocs/v1.php/cloud/users”

API_URL = base_url + Endpoint

’ Open the request
xml_obj.Open “GET”, API_URL, False ’ did try with bstrUser and bstrPassword without Auth header, but no success

’ set the header value
xml_obj.setRequestHeader “Authorisation”, “Basic stringCopiedFromPostmanTestHeader”
xml_obj.setRequestHeader “OCS-APIRequest”, “true”

’ send request to NextCloud API
xml_obj.send

'Check response
If xml_obj.Status <> 200 Then
Debug.Print xml_obj.Status & " - " & xml_obj.statusText
’ constantly getting "https://nextcloud.mydomain.com/ocs/v1.php/cloud/users
’ 401 - "
Exit Sub
Else
Debug.Print xml_obj.responseText

End If

End Sub

Is there anybody that can help me on this?
Assistance will really be appreciated.

[/details]

Nextcloud version (eg, 20.0.5): 24.0.3
PHP version (eg, 7.4): replace me
Microsoft Excel 365 on Windows 11

The issue you are facing:
Can’t get the VBA call to work

Steps to replicate it:

The output of your Nextcloud log in Admin > Logging:

(no logging happens although all levels are selected)

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):


application/x-httpd-php config.php ( PHP script text )
<?php
$CONFIG = array (
  'instanceid' => 'wefwefwe',
  'passwordsalt' => 'wefwefwef',
  'secret' => 'wfwefwefwe',
  'trusted_domains' => 
  array (
    0 => 'nextcloud.mydomain.com',
  ),
  'datadirectory' => '/home1/dsthyshsfh/data',
  'dbtype' => 'mysql',
  'version' => '24.0.3.2',
  'overwrite.cli.url' => 'https://nextcloud.mydomain.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'bmhnj',
  'dbpassword' => 'dfghj',
  'default_language' => 'en',
  'default_locale' => 'en_US',
  'force_language' => false,
  'default_phone_region' => 'ZA',
  'installed' => true,
  'knowledgebaseenabled' => true,
  'remember_login_cookie_lifetime' => 1296000,
  'session_lifetime' => 86400,
  'session_keepalive' => true,
  'auto_logout' => false,
  'auth.bruteforce.protection.enabled' => true,
  'mail_from_address' => 'xxxx',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'gmail.com',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '587',
  'mail_smtpsecure' => 'tls',
  'app_install_overwrite' => 
  array (
    0 => 'nextant',
    1 => 'printer',
    2 => 'files_lock',
    3 => 'cpanelmailsync',
    4 => 'nextbackup',
    5 => 'ownbackup',
    6 => 'loganalyzer',
    7 => 'workin2gether',
    8 => 'spreedme',
    9 => 'occweb',
  ),
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'xxxx@gmail.com',
  'mail_smtppassword' => 'dfshgrth',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'auth.webauthn.enabled' => false,
  'mysql.utf8mb4' => true,
  'updater.secret' => 'xxxxx',
);

I think that should be Authorization ?!

See HTTP authentication - HTTP | MDN

YESSSS!!! Thank you!!!