This project is read-only.
1
Vote

Trouble Creating TodoItem

description

Using your API, I created an export tool that will take a copy of the project and save it out as an excel file. It works phenomenally well. Thank you for the API!

The company then decided it wanted to upload from excel. I have it working to create the ToDoList. That is no problem. It will also create the ToDoItems if, and only if, I do not have an person assigned to the item. If I attempt to add a person, I get a 400, bad request response back. I should mention, the code below has been changed and modified as part of my trouble shooting. It had been cleaner!
  
This code is above the for loop.

                Project proj = api.Projects.Get(getProjectID(lstProject.SelectedItem.ToString()));
                IEnumerable<PersonStub> PersonList = proj.People;
                IEnumerable<ToDoListStub> ItemList = api.ToDoLists.GetActiveForProject(proj.Id);
                ToDoListStub zToDoList = null;
                ToDoListItemStub zToDoListItem = null;
                PersonStub zPerson = null;
                bool foundItem = false;


                     This code is part of a for loop:

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-Find ToDo List*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
foundItem = false;
foreach (ToDoListStub toDoList in ItemList)
{
    if (toDoList.Name == todoListName)
    {
        zToDoList = toDoList;
        foundItem = true;
        break;
    }
}

if (!foundItem)
{
    // we need to create the list
    var list = proj.CreateToDoList(todoListName);
    zToDoList = list;
    txtToDo.Text += "Created list " + todoListName + "\n";
    // reload list
    ItemList = api.ToDoLists.GetActiveForProject(proj.Id);
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*End Find ToDoList-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-* Find Person *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

if (AssignedPersonName != "")
{

    foundItem = false;
    foreach (PersonStub Person in PersonList)
    {
        if (Person.Name == AssignedPersonName)
        {
            zPerson = new PersonStub();
            zPerson.Id = Person.Id;
            zPerson.Name = Person.Name;
            
            foundItem = true;
            break;
        }
    }

}
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-End Find Person-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

// we are going to assume that we want to create all items found
// TODO: update items rather than create duplicates!
if (dueDate == Convert.ToDateTime("01/01/1990") | (dueDate == Convert.ToDateTime("1/1/0001 12:00:00 AM")))
{
    zToDoListItem = zToDoList.CreateToDo(todoItemName, null, zPerson);
    
}
else {
    zToDoListItem = zToDoList.CreateToDo(todoItemName, dueDate, zPerson);
    //zToDoListItem.Assignee = zPerson;
    //zToDoList.UpdateToDo(zToDoListItem);
    
}

If the PersonStub zPerson is null, it will add the ToDoItem.

This is the JSON request that is built.

{"content":"We need to do this 1.1","position":0,"assignee":{"id":2130883,"type":"person","name":"Derald Mullenaux"}}

This is the URL being called: (account redacted)
"https://basecamp.com/***********/api/v1/projects/3830983/todolists/10877995/todos.json"

Thanks!

Derald

comments

dmullenaux wrote Oct 10, 2013 at 7:09 PM

I hate to reply to myself, but I found the issue. From the basecamp github:
If the assignee type is unrecognized or the due_at is in a wrong format, you'll see a 400 Bad Request.
So, I modified PersonStub.cs, adding the following code.
        public string Name { get; set; }
        [JsonProperty("type")]
Now, when I get the person, I add the type, and the item is added.
 zPerson = new PersonStub();
 zPerson.Id = Person.Id;
 zPerson.Name = Person.Name;
 zPerson.Type = "Person";
Thanks again for the awesome tool!

Derald

trevorjdaniel wrote Jul 24, 2014 at 10:15 PM

I have just finished an app that copies project between accounts. it was hard work!