REST API using Body not QueryString

Hi,
I am able to connect xibo api with oauth 1.0. I can use LayoutList method to take layoutlist or use any method without problem if I use querystring (url parameters)
working example http://localhost:81/xibo/services.php?service=rest&response=xml&method=LayoutList.
but I need to use LayoutRegionLibraryAdd method which can take array of mediaIds with MediaList parameter.
working example: http://localhost:81/xibo/services.php?service=rest&method=LayoutRegionLibraryAdd&layoutId=461&regionId=550d2cf750528&mediaList=776&response=xml
but both working examples work with querstring url parameters, there is nothing in body. If you need to send more than one mediaList you should use MediaList[0]=776&MediaList[1]=777&MediaList[n]=xxx
As I see sending all parameters in querystring has some limitations, so need to send data with body, but I cannot.
I use Chrome Postman App to test api, I tried raw, text, json,
raw part
{
“service”:“rest”,
“method”:“LayoutRegionLibraryAdd”,
“layoutId”:“459”,
“response”:“json”,
“regionId”:“550a087f6e988”,
“mediaList”:“777”
}
**but the api service returns a xmds response (200), whatever you write in raw (body part) ** This response is same as http://localhost:81/xibo/services.php (the url without url parameters).

<html>
    <head>
        <title>Xmds</title>
    </head>
    <body>
        <h1>XMDS</h1>
    </body>
</html>

My question is does api accept data in body part of just querystring? And if it accepts what did I wrong? Is there a working sample of .net application to connect and send data to xibo api ?

Thanks
Michael

It definitely supports POSTING a body to the service.

Have a look at:

That uses a library we provide - admittedly for Python - but if you have a look at the code for that, the part that assembles the request is here:
http://bazaar.launchpad.net/~alexharrington/xibo/api-testsuite/view/head:/core/api-testsuite/XiboAPI.py#L176

Specifically the line:
response, content = self.__client__.request(url, method='POST', body=urllib.urlencode(dict(params)))

So the body is a urlencoded string of the parameters.

Alex

Dear Alex,
Thank you for your quick and clear answer.
I find the pyton code before, and understand that is the part but cannot find how to do in .net.
What string we should have before urlencode, is this correct?: and what should we do multiple mediaIds?

{
"service":"rest",
"method":"LayoutRegionLibraryAdd",
"layoutId":"459",
"response":"json",
"regionId":"550a087f6e988",
"mediaList":"777"
}

Thanks
Michael

I think the output of urllib.urlencode(dict(params)) would be something like:

method=LayoutRegionLibraryAdd&layoutId=459&response=xml&regionId=550a087f6e988&mediaList[0]=777

Note the xml response type. I’m 99% sure json responses aren’t implemented.

You’d then POST your request to http://server/xibo/services.php?service=rest

Thanks again Alex,
What string we should have before urllencode? I mean what would be format in body? Is my format correct?

That would depend on the functionality in .net (which I don’t use I’m afraid).

In Python, the urlencode function takes the dictionary we pass it (ie key: value) and converts it to that string. So presumably there’s an equivalent .net function, otherwise you’d have to build the string to send as the body yourself.

Alex

Ok, I see. If you can help me, it would be great.
Lets forget about .net and simulate this from Postman app (which is chrome extension, and test api calls)
I am not sure which format should I use.
This screen shot shows; if you write all parameters to querystring it works.I can use querysting but as you know it has character limit, so I have lots of media to add so querystring is not usable if you send lots of data.

But if you use body, as screen shot, it always return “XMDS” (same as you write the services.php url without any parameter, it never reads paramater from body)

I try to change content type to xml,json,text, Try to change data format to xml, json, text. Nothing help.
Thank you for your help.

Michael.

All you do is put the query string in the body and then post - please see my last message which explains that