AnsweredAssumed Answered

500 Response when trying to move content via REST API (Python)

Question asked by Jeff Shurtliff on Jan 15, 2019
Latest reply on Jan 15, 2019 by jgoldhammer

Hey all,

 

So I'm trying to build a tool where I can import a CSV of content URLs (https://example.jiveon.com/docs/DOC-1234, etc.) and a destination URL and then loop through the list and move the content to their new respective places.  Basically I'm wanting to build a Bulk Manage Content tool that doesn't pummel our users with email notifications when migrating a large number of content at one time.  (Even the Curate Tool, which we purchased, can't do this without spamming users.)

 

I've been using Using REST API to Move Content as my guideline but am using Python (with the requests library) rather than AJAX.  The script is complete but for some reason I'm getting a 500 server error response when the move call is issued.  (Shown below)

 

 

Here is an excerpt from my code that performs the work:

# Function that moves content to a new location (space)
def move_content(content_type_id,content_id,dest_type_id,dest_id):
    # Perform regular GET request for the document to establish the session
    print(dbl_indent + "Performing GET query to establish the session for Content ID " + str(content_id) + "...")
    session = requests.Session()
    get_query_url = base_url + "/api/core/v3/contents?filter=entityDescriptor(" + content_type_id + "," + content_id + ")"
    session.auth = (api_username, api_password)

    # Perform the API lookup to get the User ID
    r = session.get(get_query_url, auth=(api_username, api_password))
    content_json = r.json()
    content_headers = r.headers
    content_request_headers = r.request.headers
    print(dbl_indent + "The GET request for Content ID " + str(content_id) + " returned a " + str(r.status_code) + " status code.")

    # Perform the move request within the previously established session
    move_query_url = base_url + "/__services/v2/rest/content/" + str(content_type_id) + "/" + str(content_id)
    payload = "{objectType: " + str(dest_type_id) + ", objectID: \"" + str(dest_id) + "\", notifyStreams: false}"
    print(dbl_indent + "Query URL: " + move_query_url)
    print(dbl_indent + "Payload: " + payload)
    r = session.put(move_query_url, data=payload, headers={"Content-Type":"application/json", "Accept":"application/json"})
    print(dbl_indent + "Move response for Content ID " + str(content_id) + ": " + str(r))
    move_response = r
    
    # Return the bundled query data
    query_data = (content_json, content_headers, content_request_headers, move_response)
    return query_data

# Excerpt of the code that calls the move_content function for a row in the CSV
query_data = move_content(content_type_id,content_id,container_type_id,destination_id)

 

 

Has anyone managed to do this successfully and/or does anyone have any ideas of where I could be going wrong?

 

Thanks!!

Jeff

Outcomes