chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

invalid session with set_note_attachment #50

Closed openhealth closed 13 years ago

openhealth commented 13 years ago

Hi all, when using set_note_attachment, I get an invalid session error coming from the sugarcrm side. Here is my example code:

SugarCRM.connect(Cust::SUGAR_URL, Cust::SUGAR_USERNAME, Cust::SUGAR_PASSWORD) ... File.open(path, 'w') {|f| f.write(data_bytes) } file = File.read("/tmp/hello.pdf") n = SugarCRM::Note.new n.name = "blah" n.team_name = 'global' n.team_count = 1 n.save

n.id is true and valid.

SugarCRM.connection.set_note_attachment(n.id, "hello.pdf", file)

At this point, an error occurs in the sugarcrm log: [4517][-none-][ERROR] 11: Invalid Session ID
The session ID is invalid

I can't work out why it's doing it. The json that gets sent appears to be valid, and get_note_attachment works fine. I then created a standalone app without using the sugarcrm gem and called set_note_attachment directly and this worked fine, so as far as I can tell, it seems to be an issue with the sugarcrm gem. Testing on sugarcrm version 6.1.

Any ideas? Thank you for any help...

chicks commented 13 years ago

Can you enable debugging on the connection with:

SugarCRM.connect(Cust::SUGAR_URL, Cust::SUGAR_USERNAME, Cust::SUGAR_PASSWORD. {:debug => true})

and paste the output of the JSON request/response for set_note_attachment?

openhealth commented 13 years ago

Sure no probs, here it is:

set_note_attachment: Request: { "session": "veruqtjviqq05pfq4m2j2jkh94", "note": { "id": "200e66a1-7a8c-02cb-2559-4dc0a9cc7db6", "filename": "hello.pdf", "file": "JVBERi0xLjMKJf////8KMSAwIG9iago8PCAvQ3JlYXRvciAoUHJhd24pCi9Q cm9kdWNlciAoUHJhd24pCj4+CmVuZG9iagoyIDAgb2JqCjw8IC9Db3VudCAx Ci9LaWRzIFs1IDAgUl0KL1R5cGUgL1BhZ2VzCj4+CmVuZG9iagozIDAgb2Jq Cjw8IC9UeXBlIC9DYXRhbG9nCi9QYWdlcyAyIDAgUgo+PgplbmRvYmoKNCAw IG9iago8PCAvTGVuZ3RoIDM1OQo+PgpzdHJlYW0KL0RldmljZVJHQiBjc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UgZiAKMDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAw MDcxIDAwMDAwIG4gCjAwMDAwMDAxMjggMDAwMDAgbiAKMDAwMDAwMDE3NyAw MDAwMCBuIAowMDAwMDAwNTg3IDAwMDAwIG4gCjAwMDAwMDA3NzcgMDAwMDAg biAKMDAwMDAwMDg4MiAwMDAwMCBuIAp0cmFpbGVyCjw8IC9TaXplIDgKL1Jv b3QgMyAwIFIKL0luZm8gMSAwIFIKPj4Kc3RhcnR4cmVmCjk3OQolJUVPRgo= ", "related_module_id": "", "related_module_name": "" } }

set_note_attachment: JSON Response: {"number"=>11, "name"=>"Invalid Session ID", "description"=>"The session ID is invalid"}

chicks commented 13 years ago

Ahhh... there's a newline at the end of the base64 encoded file string. I've fixed this in HEAD, but I need to cut another gem. Let me patch up some of the tests and get this released.

openhealth commented 13 years ago

Ah no worries, thank you =)

chicks commented 13 years ago

Okay, give gem version 0.9.14 a spin and let me know if that fixes things.

openhealth commented 13 years ago

Ah excellent, this has fixed the issue! Thanks very much.

chicks commented 13 years ago

Suh-weet.