iPhone + JSON + services + drupal - problems with node.save and file.save

Events happening in the community are now at Drupal community events on www.drupal.org.
roo's picture

I have two issues I am hoping someone can assist with.

Running Drupal 6.16, services 6.x-2.0, json server 6.x-2.0-alpha1.

Have API disabled, sessid enabled.

Can connect, login and retrieve/parse views and nodes with node.get and views.get.

but have no luck with file.save and node.save.

example file.save = method="node.save"&sessid="aeufrgi2kk1tm1ra8rfacg9et5"&node="{"uid":"5","title":"newcontent","type":"mytype","name":"testuser","body":""}"

the user can create content via the web site with these values, but via the services call they get:

{
"#error" = 1;
"#message" = "Access denied";
}

and with the file.save, I try a post like:

method="file.save"&sessid="aeufrgi2kk1tm1ra8rfacg9et5"&file="{"filemime":"image/jpeg","fid":"","status":"1","file":"%2F9j%2F4AAQS... HEAPS OF BASE 64 image data ....","uid":"5","filesize":"53675","timestamp":"1269266556","filename":"CEE53B84-CE0C-480E-9BA7-C711295F15E0-11709-00003A626C868B2E.jpg","filepath":"sites/default/files/previewimage/CEE53B84-CE0C-480E-9BA7-C711295F15E0-11709-00003A626C868B2E.jpg"}"

the directory exists, but the call returns a plain "0", no error message or JSON block.

I have been trying to resolve this for 4 days now and am rapidly getting nowhere, I have tried many variations of the calls, such as not including the "Fid" parameter, and/or the status, etc.

Any ideas? Anyone? Please??

Andrew

Comments

json server 6.x-2.0-alpha1 is

skyredwang's picture

json server 6.x-2.0-alpha1 is broken! Use the old version + heyrocker's patch instead

hello

surbhipatel's picture

Hello skyredwang

Can you please tell me from were do we have to find this patch? I have enable services 2.0 + json_server alpha module on my site.Actually I am a new bee to all this webservices thing. We have requirement from client for scheduling the events through drupal and integrating with android apps.Whenever I click on JSON - /services/json link on services page I get error "{ "#error": true, "#data": "Invalid method " }". What I need to do the set up.

Please help , your help will be really precious to us.

check your PHP version.

skyredwang's picture

check your PHP version. Json_server has compatibility issue with latest version of PHP. Use something before 5.2.8.

Or use the JSONRPC Server

voxpelli's picture

Or use the JSONRPC Server which follows the JSON-RPC standard or the REST Server which also supports JSON as a response format.

thanks

roo's picture

Thanks guys, will look into that. It would have saved me some time if the fact it was broken was on the JSON_Server page though. I guess that's what I get for using an "alpha" :(

Thanks again.

roo's picture

OK.

I went with JSON-RPC server, it seemed the logical choice (6.x-2.0-beta2)

However, after realising json_decode was not in php 5.1.6 - I hacked the upgrade to 5.2.11.

But now I am getting:

PHP Fatal error: Call to undefined function services_controller_get() in /var/www/html/modules/jsonrpc_server/JsonRpcServer.php on line 43

Where is this going wrong? I cannot find a reference to this function anywhere. Is it a broken include?

Andrew

JsonRPC 2.x is intended for

Hugo Wetterberg's picture

JsonRPC 2.x is intended for use with services 3.x. If you want to use services 2.x you should download the 1.x version.

ok

roo's picture

got it running now with jsonrpc 1.x

thanks,
closed...

Can get it running for the iPhone

ncatdesigner's picture

I just installed JSON-RPC and JSON servers

I'm trying to make a request to the server but I can make it work, because I don't know how to build the request

For now All i got is...

responseData = [[NSMutableData data] retain];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://**************/services/json-rpc"]];

NSString *jsonString = @"{\"jsonrpc\": \"2.0\",\"method\": \"node.get\", \"params\": { \"arg1\": 1 } ,\"id\": \"dsadasdas\"}";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];

[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: jsonData ];
[ request setValue:@"application/json" forHTTPHeaderField:@"Content-> Type"];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

I think the problem is the jsonstring

Any idea??

It might be the UTF32

Hugo Wetterberg's picture

It might be the UTF32 encoding that's causing the problems, and you should never hand-code json or other data formats. Other than that I would suggest that you take a look at the rest server and the api-cleanup branch of my HBaseLibrary: http://github.com/hugowetterberg/HBaseLibrary/tree/api-cleanup

This tutorial is a bit outdated, but should give you some pointers: http://goodold.se/blog/tech/integrate-iphone-app-drupal

There's also the DocuWalk app: http://github.com/hugowetterberg/docuwalk-app
...which I haven't had time to polish up with guides etc. But it should serve as a mini-guide to integrating with Drupal using services and HBaseLibrary.

There's also the guide to writing services and creating endpoints using services 3.x: http://github.com/hugowetterberg/services-3.x-sample/blob/master/creatin...

Cheers,
Hugo

need to configure?

zarkinfrood's picture

do we need to setup arguments in /admin/build/services/browse/node.save in order for this to work?

I get 301 redirect errors anytime I try to use curl to access any methods

Thanks .. for sharing it

mobileprogramming's picture

Hello Guyzzz.... I am facing the same problem. It will help my drupal developers surely... I have shared this wonderful post with my team.. Thanx for sharing these technical details !!!!

Regards,
Mobile Programming LLC
http://www.mobileprogramming.com

I saw the whole conversation

rachel_clark's picture

I saw the whole conversation and really thanks to those who gave reply to the thread. Actually i had also such kind of problem and after seeing this thread i got an idea to resolve it. Thanks all !

Regards..
Android Apps Development
http://www.androidapplicationdevelopments.com

Thanks God I work with

Dalter's picture

Thanks God I work with android software development mainly as iOs have too much thing to remember about!

Thanks for contributing your

kylebrowning's picture

Thanks for contributing your valuable point.

Kyle, those last four are

Hugo Wetterberg's picture

Kyle, those last four are just spambots/spammers

how to find this patch?Use

sangitashankar's picture

how to find this patch?Use the old version + heyrocker's patch instead Other than that I would suggest that you take a look at the rest server and the api-cleanup branch.Software development company

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: