Welcome Guest Login Register Member List
ExpressionEngine Forums
Advanced Search
Username: Password:
Remember Me? forgot password?
You are here: Forum Home  >  Usage  >  Troubleshooting  >  Thread
   
 
Adding Note to project via HTTP POST
 
concept
Posted: 03 February 2010 06:10 AM   [ Ignore ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

I’m trying to add the ability of adding a note to a project from Outlook by adapting the method used to add activities (http://github.com/lrbalt/outlookemailtotracks).

It’s not working, and it may be a permission error, but I have no idea…

Please take a look at the log below, and let me know if I’m doing something wrong.  Up until the “Mysql::Error: Column ‘project_id’ cannot be null” error, the log resembles the logging of a successful addition of an activity using the method linked above.

When adding an activity, first there is a 401 Unauthorized response, and then it executes again and returns 201 Created.  When adding a note, first there is a 401 Unauthorized response, and then it executes again, fails with “Mysql::Error: Column ‘project_id’ cannot be null”, and returns 500 Internal Server Error.  But from looking at the log, how can ‘project_id’ be null when the log clearly states “Parameters: {“note”=>{“project_id”=>” 1”, “body”=>“Just a reminder…”?

I realize there is a space before the 1, which I found to be an odd result of the original VBA method using Str(ProjectID) instead of CStr(ProjectID).  I changed it to CStr, and there was no longer a space, but I got the exact same error.

Any ideas?

Thanks!

Profile
 
concept
Posted: 03 February 2010 06:13 AM   [ Ignore ]   [ # 1 ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

End of trace cut off by 6000 character limit…

Processing NotesController#create to xml (for 192.168.1.1 at 2010-02-02 23:17:44) [POST]
  
Session ID: dd6a279d3d06882f820a833bfe38ee1d
  Parameters
: {"note"=>{"project_id"=>" 1", "body"=>"Just a reminder that we do not have a game this week. \240I will let you know the playoff schedule by Friday this week.\n\nThanks,\n\n\240\n\nSteve \n\n\240\n"}}
Filter chain halted 
as [:login_required] rendered_or_redirected.
Completed in 2ms (View: 0, DB: 2) | 401 Unauthorized [http://www.khristhansen.com/notes.xml]


Processing NotesController#create to xml (for 192.168.1.1 at 2010-02-02 23:17:44) [POST]
  
Session ID: dd6a279d3d06882f820a833bfe38ee1d
  Parameters
: {"note"=>{"project_id"=>" 1", "body"=>"Just a reminder that we do not have a game this week. \240I will let you know the playoff schedule by Friday this week.\n\nThanks,\n\n\240\n\nSteve \n\n\240\n"}}


ActiveRecord
::StatementInvalid (Mysql::Error: Column 'project_id' cannot be null: INSERT INTO `notes` (`project_id`, `updated_at`, `body`, `user_id`, `created_at`) VALUES(NULL, '2010-02-03 05:17:44', NULL, 1, '2010-02-03 05:17:44')):
    /
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:309:in 
`execute'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:171:in `insert_sql'
    
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:319:in `insert_sql'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in 
`insert_without_query_dirty'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
    
/vendor/rails/activerecord/lib/active_record/base.rb:2733:in `create_without_callbacks'
    /vendor/rails/activerecord/lib/active_record/callbacks.rb:237:in 
`create_without_timestamps'
    /vendor/rails/activerecord/lib/active_record/timestamp.rb:29:in `create'
    
/vendor/rails/activerecord/lib/active_record/base.rb:2699:in `create_or_update_without_callbacks'
    /vendor/rails/activerecord/lib/active_record/callbacks.rb:222:in 
`create_or_update'
    /vendor/rails/activerecord/lib/active_record/base.rb:2383:in `save_without_validation'
    
/vendor/rails/activerecord/lib/active_record/validations.rb:1009:in `save_without_dirty'
    /vendor/rails/activerecord/lib/active_record/dirty.rb:79:in 
`save_without_transactions'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:179:in `send'
    
/vendor/rails/activerecord/lib/active_record/transactions.rb:179:in `with_transaction_returning_status'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in 
`transaction'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:129:in `transaction'
    
/vendor/rails/activerecord/lib/active_record/transactions.rb:138:in `transaction'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:178:in 
`with_transaction_returning_status'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:146:in `save'
    
/vendor/rails/activerecord/lib/active_record/transactions.rb:158:in `rollback_active_record_state!'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:146:in 
`save'
    /app/controllers/notes_controller.rb:32:in `create'
    
/vendor/rails/actionpack/lib/action_controller/base.rb:1253:in `send'
    /vendor/rails/actionpack/lib/action_controller/base.rb:1253:in 
`perform_action_without_filters'
    /vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
    
/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
    /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in 
`perform_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    
/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in 
`perform_action_without_caching'
    /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `passenger_orig_perform_action'
    
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in 
`cache'
    /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in `passenger_orig_perform_action'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/request_handler.rb:65:in `perform_action'
    /vendor/rails/actionpack/lib/action_controller/base.rb:524:in 
`send'
    /vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'
    
/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
    /vendor/rails/actionpack/lib/action_controller/session_management.rb:134:in 
`process'
    /vendor/rails/actionpack/lib/action_controller/base.rb:392:in `process'
    
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:183:in `handle_request'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in 
`dispatch_unlocked'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in `dispatch'
    
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `synchronize'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in 
`dispatch'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
    
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:39:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/request_handler.rb:50:in 
`process_request 
Profile
 
concept
Posted: 03 February 2010 06:17 AM   [ Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

Rest of the trace…

/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:378:in 
`start_request_handler'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:336:in `handle_spawn_application'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/utils.rb:183:in `safe_fork'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:334:in 
`handle_spawn_application'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in 
`start_synchronously'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:163:in `start'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:262:in 
`spawn_rails_application'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:80:in 
`synchronize'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:154:in 
`spawn_application'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in 
`main_loop'
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
    
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/bin/passenger-spawn-server:61

Rendering 
/var/data/tracks/public/500.html (500 Internal Server Error) 
Profile
 
concept
Posted: 03 February 2010 09:06 AM   [ Ignore ]   [ # 3 ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

It looks like there are some differences in the table structures.  I’m particularly concerned about differences between the ‘user_id’ and ‘project_id’ columns.

Could this be the source of my problem?

--
-- 
Table structure for table `todos`
--

DROP TABLE IF EXISTS `todos`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; CREATE TABLE `todos` (
  `
id` int(11) NOT NULL auto_increment,
  `
context_id` int(11) NOT NULL,
  `
project_id` int(11) default NULL,
  `
description` varchar(255) NOT NULL,
  `
notes` text,
  `
created_at` datetime default NULL,
  `
due` datetime default NULL,
  `
completed_at` datetime default NULL,
  `
user_id` int(11) default '1',
  `
show_from` datetime default NULL,
  `
state` varchar(20) NOT NULL default 'immediate',
  `
recurring_todo_id` int(11) default NULL,
  `
updated_at` datetime default NULL,
  
PRIMARY KEY  (`id`),
  
KEY `index_todos_on_user_id_and_state` (`user_id`,`state`),
  
KEY `index_todos_on_user_id_and_project_id` (`user_id`,`project_id`),
  
KEY `index_todos_on_project_id` (`project_id`),
  
KEY `index_todos_on_context_id` (`context_id`),
  
KEY `index_todos_on_user_id_and_context_id` (`user_id`,`context_id`)
) 
ENGINE=InnoDB AUTO_INCREMENT=4939 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */; 
--
-- 
Table structure for table `notes`
--

DROP TABLE IF EXISTS `notes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; CREATE TABLE `notes` (
  `
id` int(11) NOT NULL auto_increment,
  `
user_id` int(11) NOT NULL,
  `
project_id` int(11) NOT NULL,
  `
body` text,
  `
created_at` datetime default NULL,
  `
updated_at` datetime default NULL,
  
PRIMARY KEY  (`id`),
  
KEY `index_notes_on_project_id` (`project_id`),
  
KEY `index_notes_on_user_id` (`user_id`)
) 
ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */; 
Profile
 
Reinier Balt
Posted: 03 February 2010 03:57 PM   [ Ignore ]   [ # 4 ]  
Sr. Member
RankRankRankRank
Total Posts:  579
Joined  2006-10-05

I do not think Tracks is tested for adding notes using REST api. If you look at the INSERT statement, no data from the request is passed into the sql… Looking closer, REST is not implemented for notes…

Profile
 
Reinier Balt
Posted: 03 February 2010 04:11 PM   [ Ignore ]   [ # 5 ]  
Sr. Member
RankRankRankRank
Total Posts:  579
Joined  2006-10-05

I just tested. It does work when you use new_note instead of note, like:

curl -H ‘Accept: application/xml’ -H ‘Content-Type: application/xml’ -u user:password -d ‘<new_note>67</project_id><body>test</body></new_note>’ http://tracks.mydomain.com/notes.xml

this is obviously not correct grin We need to change new_note into note

Profile
 
Reinier Balt
Posted: 03 February 2010 04:41 PM   [ Ignore ]   [ # 6 ]  
Sr. Member
RankRankRankRank
Total Posts:  579
Joined  2006-10-05

I think I fixed this in git.

Profile
 
concept
Posted: 04 February 2010 04:32 AM   [ Ignore ]   [ # 7 ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

Thanks for looking into this!

I will use new_note until the next stable release.

Also, I was able to add Due Date to the Outlook integration.  I’m guessing I can’t do Show From date and keywords because they’re kept in a different table.  Is that right?  If so, do they have their own XML files that can be updated through subsequent HTTP POSTs?

Thanks again for all of the help.  My goal within a year is to build a synchronization mechanism for Tracks and Outlook.

Profile
 
concept
Posted: 04 February 2010 04:59 AM   [ Ignore ]   [ # 8 ]  
Newbie
Rank
Total Posts:  7
Joined  2010-02-03

Nevermind, I found the docs.

Thanks again!

Profile
 
Reinier Balt
Posted: 04 February 2010 08:12 AM   [ Ignore ]   [ # 9 ]  
Sr. Member
RankRankRankRank
Total Posts:  579
Joined  2006-10-05

That would be great. I can’t find the time to bring the outlook plugin further…

Show From is part of a todo, so you should be able to set it using REST, but the tags are a seperate resource with its own tables (plural)

Profile
 
   
 
 
‹‹ Database update 1.7 -> devel      "Add Action" button behavior ››

Powered By ExpressionEngine
Template Design By Sonnenvogel.com
Select a theme:

ExpressionEngine Discussion Forum - Version 2.1.2 (20091002)
Script Executed in 0.1546 seconds

Atom Feed
RSS 2.0