For those looking for an anwser to this, i found it:
def copy_between_sites(username, password, site_url, origin_url, destination_url):
# copy a file from one location in sharepoint to another location, can be in a different site
origin = str(site_url + origin_url).replace(' ', '%20')
destination = str(site_url + destination_url).replace(' ', '%20')
destination = destination.rstrip(destination[-1])
auth = AuthenticationContext(site_url)
if auth.acquire_token_for_user(username, password):
request = ClientContext(site_url, auth)
options = RequestOptions("{0}/sites/<your site>/_api/site/CreateCopyJobs".format(site_url))
options.method = HttpMethod.Post
options.data = {
"exportObjectUris": [
origin
],
"destinationUri": destination,
"options": {
"IgnoreVersionHistory": True,
"IsMoveMode": False,
"BypassSharedLock": True
}
}
options.headers = {
"X-RequestDigest": str(getToken(username=username_shrpt, password=password_shrpt, site_url=origin))
}
data = request.execute_request_direct(options)
output = json.loads(data.content)
else:
print(auth.get_last_error())
return
def getToken(username, password, site_url):
# get the digest value from the site, for write access
contextinfo_api = site_url + "/_api/contextinfo"
auth = AuthenticationContext(site_url)
if auth.acquire_token_for_user(username,password):
request = ClientContext(site_url, auth)
options = RequestOptions(contextinfo_api)
options.method = HttpMethod.Post
data = request.execute_request_direct(options)
output = json.loads(data.content)
digest_value = output['d']['GetContextWebInformation']['FormDigestValue']
else:
print(auth.get_last_error())
return digest_value