import requests


def create_private_contribution(username="",password=""):
    """
    Create a private contribution on earthref.org/MagIC.

    Parameters
    ----------
    username : str
        personal username for MagIC
    password : str
        password for username

    Returns
    ---------
    response: API requests.models.Response
        response.status_code: bool
            True : successful creation of private workspace
        response['url'] : str
            URL of request
        response['method']='POST'
        response['id'] : str
            if successful, MagIC ID number created
        response['errors'] : str
            if unsuccessful, error message
    """
    api = 'https://api.earthref.org/v1/MagIC/{}'
    response={}
    response['status_code']=False
    response['errors']='Failed to contact database'
    response['status_code']=False
    response['method']='POST'
    try:
        create_response = requests.post(api.format('private'), auth=(username, password))
        if create_response.status_code==201:
            response['status_code']=True
            response['errors']=None
            response['method']='POST'
            response['url']=create_response.request.url
            response['id']=create_response.json()['id']
        else:
            response['status_code']=False
            response['method']='POST'
            response['url']=create_response.request.url
            response['id']='None'
            response['errors']=create_response.json()['errors'][0]['message']
    except:
        pass
    return response