Programmatically create external storage

Nextcloud version: 15.0.5
Operating system and version: Official Docker FPM image

The issue you are facing:
Hey guys, my Google Fu is failing me so forgive me if this has been answered already. At my company I’m trying to automate user provisioning and external storage creation using Python. I can do everything using Python3 requests except create the external storage. With the Firefox web dev tools open, I copied the result of creating an external storage point using the web UI as a curl command and got this (reformatted to make reading easier for me):

curl '' 
    -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0' 
    -H 'Accept: */*' 
    -H 'Accept-Language: en-US,en;q=0.5' 
    -H 'Content-Type: application/json' 
    -H 'requesttoken: token here' 
    -H 'OCS-APIREQUEST: true' 
    -H 'X-Requested-With: XMLHttpRequest' 
    -H 'DNT: 1' 
    -H 'Connection: keep-alive' 
    -H 'Cookie: cookie here' 
    -H 'TE: Trailers' 
    --data '{

Now, if I delete the bucket in the UI and run the curl command, it successfully (re)creates the bucket. However, in Python when I try it I keep getting a “User is not logged in” error. I’ve even tried to recreate things as close to the curl command as possible.

CREATEJSON = '{"mountPoint":"foo",' \
             '"backend":"amazons3",' \
             '"authMechanism":"amazons3::accesskey",' \
             '"backendOptions":{' \
                '"bucket":"mymountpoint",' \
                '"hostname":"",' \
                '"port":"",' \
                '"region":"myregion",' \
                '"use_ssl":true,' \
                '"use_path_style":false,' \
                '"legacy_auth":false,' \
                '"key":"mykey",' \
                '"secret":"mysecret"},' \
             '"testOnly":true,' \
             '"mountOptions":{' \
                '"encrypt":true,' \
                '"previews":true,' \
                '"enable_sharing":false,' \
                '"filesystem_check_changes":1,' \
                '"encoding_compatibility":false,' \
                '"readonly":false},' \
             '"applicableUsers":[],' \
             '"applicableGroups":[],' \

session = requests.session()

# Login to get our auth cookie
loginAuth = session.get("",
                        auth=("myuser", "mypassword"),
                                     "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0"},
                        data={"OCS-APIREQUEST": "true"})

# Get the CSRF token
lxmlParse = lxml.html.fromstring(loginAuth.text)
headerXpath = lxmlParse.xpath("//head")[0]
requestToken = headerXpath.get("data-requesttoken")

# Set the auth cookie
authCookie = loginAuth.headers["Set-Cookie"]

createStorage ='',
                             headers={"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0",
                                      "Accept": "*/*",
                                      "Accept-Language": "en-US,en;q=0.5",
                                      "Content-Type": "application/json",
                                      "requesttoken": requestToken,
                                      "OCS-APIREQUEST": "true",
                                      "X-Requested-With": "XMLHttpRequest",
                                      "Connection": "keep-alive",
                                      "Cookie": authCookie,
                                      "TE": "Trailers"},

I’ve got to the point where I can’t see what’s wrong/different here. Can someone point me in the right direction or let me know if it’s not possible to create an external storage point this way? Thanks much!