problem with function parameter while sending a post request to the web service

Hi developers.

I don't know how to process incoming parameters sent from client with post request.

I always receive this error: x parameter is missing.

suppose i have this exposed function:


function blog_save($username, $title, $text, $excerpt = "", $tags = "blog" , $access = ACCESS_PUBLIC) {
	$user = get_user_by_username($username);
	if (!$user) {
		throw new InvalidParameterException('registration:usernamenotvalid');
	$obj = new ElggObject();
	$obj->subtype = "blog";
	$obj->owner_guid = $user->guid;
	$obj->access_id = strip_tags($access);
	$obj->method = "api";
	$obj->description = strip_tags($text);
	$obj->title = elgg_substr(strip_tags($title), 0, 140);
	$obj->status = 'published';
	$obj->comments_on = 'On';
	$obj->excerpt = strip_tags($excerpt);
	$obj->tags = strip_tags($tags);
	$guid = $obj->save();
	$return['success'] = true;
	$return['message'] = elgg_echo('blog:message:saved');
	return $return;

				array('username' => array ('type' => 'string', 'required' => true),
						'title' => array ('type' => 'string', 'required' => true),
						'text' => array ('type' => 'string', 'required' => true),
						'excerpt' => array ('type' => 'string', 'required' => false),
						'tags' => array ('type' => 'string', 'required' => false),
						'access' => array ('type' => 'string', 'required' => false),
				"Post a blog post",

I have written a simple client code using java. here is my code:



JSONObject object = new JSONObject();
            String userName = "manatech";
            object.put("username", userName);
            String blogTitle="Test title";
            object.put("title", blogTitle);
            String text = "This is blog body for testing";
            object.put("text", text);
            String excerpt = "This is some excerpt";
            object.put("excerpt", excerpt);
            String tags = "some_tag";
            object.put("tags", tags);
            String access = "ACCESS_PUBLIC";
            object.put("access", access);
            CloseableHttpClient client = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("http://localhost/elgg/services/api/rest/json?method=blog.save_post");
            StringEntity entity = new StringEntity(object.toJSONString());
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");

            CloseableHttpResponse response = client.execute(httpPost);
            if (response.getStatusLine().getStatusCode() == 200)
                        System.out.println("Execution success");
            //Code to print out the result are scaped

I always receive this result


{"status":-1,"message":"Missing parameter username in method blog.save_post"}

I think parameters sent from client did not associate with parameters on exposed function blog.save_post.

Please help



Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking