Web component - request header for Booked (phpScheduleIT)

532 views
Skip to first unread message

Andrea Blacktea

unread,
Dec 2, 2015, 10:01:34 AM12/2/15
to MIT App Inventor Forum
Hi, i'm building up an App that send and receive data from Booked (http://www.bookedscheduler.com) .

API are supported (as described in http://allsaintsbrookline.org/schedule/Web/Services/ )

I can authenticate the user correctly and i made the right blocks to use API passing the token and userid .... unfortunately i deleted those blocks ( :( ) and now i can't remember what i did.

I'm trying to reconstruct them in the last 2 days but i can't figure what i need.

I need to pass the token and userid by request headers ( web.requestheaders -> make a list -> make a list -> ? )

Anyone can help me?

Thank you in advance!

Andrea Blacktea

unread,
Dec 2, 2015, 2:09:53 PM12/2/15
to MIT App Inventor Forum
These are my blocks at the moment
query booked.jpg

Taifun

unread,
Dec 2, 2015, 2:25:23 PM12/2/15
to MIT App Inventor Forum

RequestHeaders
The request headers, as a list of two-element sublists. The first element of each sublist represents the request header field name. The second element of each sublist represents the request header field values, either a single value or a list containing multiple values.

also you should remove your brackets, commas, colons and double quotes...

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.                

Andrea Blacktea

unread,
Dec 2, 2015, 2:41:04 PM12/2/15
to MIT App Inventor Forum
I have modified this way ...

Now i login and the app correctly get token and userid as before, i launch the reservation-thing and i receive nothing.

I have a field to see what is responseContent and noone appears.

If i launch reservation one more time it goes 401 error again :(
query booked.jpg

Andrea Blacktea

unread,
Dec 2, 2015, 3:13:41 PM12/2/15
to MIT App Inventor Forum
It works!

Last version of blocks (did what Taifun suggested) works well ... the problem, this time, was that App Inventor sometimes mix my blocks (when i save and close and then open again the progect)

Thank you Taifun!
Message has been deleted

Andrea Blacktea

unread,
Dec 5, 2015, 5:05:09 AM12/5/15
to MIT App Inventor Forum
Another problem :-/

I'm going to create a new user via-API but it seems that App Inventor doesnt mind of what i put in Posttext.text block.

The API gives me back all the registered users (and that happens when i post to this address without any other text)

It is strange cause the authorization process uses the same blocks (as seen in the attached image) and works well.
booked_query.png
booked_query_auth.png

Taifun

unread,
Dec 5, 2015, 1:26:56 PM12/5/15
to MIT App Inventor Forum
are you able to create a new user successfully?
and as response you get back a list of all users, is that correct?
probably that API is designed like that?
Taifun

Blacktea

unread,
Dec 5, 2015, 1:50:01 PM12/5/15
to MIT App Inventor Forum
Yes, i can create a new one.

There is a small tool (called Booked tester that can help in debugging)

Here it is what it says (and successfully create a new user)
-------------------------------------------------------------------------------------------------------------------
-1 route chosen is http://xx.xx.xx.xx/booked/Web/Services/index.php/Users/
   secure is True
   header type is POST
   service request is CreateUser
   sessionToken is
   userId is
-1  $authroute is http://xx.xx.xx.xx/booked/Web/Services/index.php/Authentication/Authenticate
   $authbody is {"username":"admin","password":"xxx"}
-1  ********** Making the call to Authenticate **********
-1 sessionToken =
-1 userId =
-1  status = 200
-1  reply = {"sessionToken":"5663316ac76d3","sessionExpires":"2015-12-05T19:18:10+0000","userId":"2","isAuthenticated":true,"links":[{"href":"http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Authentication\/SignOut","title":"logout"}],"message":null}
-1  response = {"sessionToken":"5663316ac76d3","sessionExpires":"2015-12-05T19:18:10+0000","userId":"2","isAuthenticated":true,"links":[{"href":"http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Authentication\/SignOut","title":"logout"}],"message":null}
-1  sessionToken = 5663316ac76d3
-1  userId = 2
-1  isAuthenticated = True
-1  secure = True
-1  sessionExpires = 2015-12-05T19:18:10+0000
-1  ************  Making the call to  ************ 
=> http://xx.xx.xx.xx/booked/Web/Services/index.php/Users/
=> body = {"password":"maxmax","language":"en_us","firstName":"max","lastName":"max","emailAddress":"m...@max.com","userName":"maxmax","timezone":"America/Chicago","phone":"","organization":"","position":"","customAttributes":[{"attributeId":"3","attributeValue":"Steve Majors"},{"attributeId":"5","attributeValue":"Yes"}]}
-1 sessionToken = 5663316ac76d3
-1 userId = 2
-1 ************ HERE IS THE FINAL DATA *************
=> header_type is POST
=> route is http://xx.xx.xx.xx/booked/Web/Services/index.php/Users/
=> body is {"password":"maxmax","language":"en_us","firstName":"max","lastName":"max","emailAddress":"m...@max.com","userName":"maxmax","timezone":"America/Chicago","phone":"","organization":"","position":"","customAttributes":[{"attributeId":"3","attributeValue":"Steve Majors"},{"attributeId":"5","attributeValue":"Yes"}]}
=> adding the header for authentication
==> X-Booked-SessionToken:5663316ac76d3
==> X-Booked-UserId:2
-1  status = 201
-1  reply = {"userId":13,"links":[{"href":"http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Users\/:userId","title":"get_user"},{"href":"http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Users\/:userId","title":"update_user"}],"message":null}


 *************** Reply in an Easier-To-Read Format ***************
{
  "userId": 13
  "links": [
    {
      "href": "http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Users\/:userId"
      "title": "get_user"
    }
    {
      "href": "http:\/\/xx.xx.xx.xx\/booked\/Web\/Services\/index.php\/Users\/:userId"
      "title": "update_user"
    }
  ]
  "message": null
}
---------------------------------------------------------------------------------------------------------

Taifun

unread,
Dec 5, 2015, 2:00:54 PM12/5/15
to MIT App Inventor Forum
Yes, i can create a new one.
so what exactly is your issue?
Taifun

Blacktea

unread,
Dec 5, 2015, 2:51:39 PM12/5/15
to MIT App Inventor Forum
what i need is to replicate in App Inventor what  that "Booked_Tester" can do.

I dont understand why my blocks dont work (as i said, what i add in "call crea_utente.PostText" seem dont affect the result)

Blacktea

unread,
Dec 5, 2015, 3:37:10 PM12/5/15
to MIT App Inventor Forum
Ah, i can create new user via Booked-Tool, not App Inventor

Blacktea

unread,
Dec 7, 2015, 7:04:03 AM12/7/15
to MIT App Inventor Forum
anyone can help?
Thank you in advance :)

Taifun

unread,
Dec 7, 2015, 9:02:47 AM12/7/15
to MIT App Inventor Forum
add again a screenshot of your relevant App Inventor blocks including the WebGotText event. Also which response do you get back from that API?
Then explain, what you want to happen and what happens instead
Taifun

Blacktea

unread,
Dec 7, 2015, 2:38:47 PM12/7/15
to MIT App Inventor Forum
Hi Taifun, with the blocks attached i want to pass to the API at http://myipserver/booked/Web/Services/Users/ 
the following text: {"password":"maxmax","language":"en_us","firstName":"max","lastName":"delise","emailAddress":"m...@m.it","userName":"max","timezone":"Europe/Rome","phone":"","organization":"","position":"","customAttributes":[{"attributeId":"3","attributeValue":"Steve Majors"},{"attributeId":"5","attributeValue":"Yes"}]}

Instructions says that this is the right way to create a user (using a Windows application called Booked Tester i can simulate my Android App and it works).

When i send it using App Inventor Companion it doesnt create a new user .... it gives me the list of already created users (that is the result i receive if i use the API Getallusers)......

http://myipserver/booked/Web/Services/Users/  it is the same address for both API Createuser and Getallusers but without the post text (and that is why i think my post text isn't recognized by API)

Last thing ... Createuser should use POST, Getallusers should use GET.

Sorry for english, it's not my Language :)
booked_query.png

Taifun

unread,
Dec 7, 2015, 3:33:31 PM12/7/15
to MIT App Inventor Forum
your blocks look fine...
what happens, if you post the complete text?

{"password":"maxmax","language":"en_us","firstName":"max","lastName":"delise","emailAddress":"m...@m.it","userName":"max","timezone":"Europe/Rome","phone":"","organization":"","position":"","customAttributes":[{"attributeId":"3","attributeValue":"Steve Majors"},{"attributeId":"5","attributeValue":"Yes"}]}

Taifun

Blacktea

unread,
Dec 7, 2015, 3:37:54 PM12/7/15
to MIT App Inventor Forum
i post all the text ... in the image you see a part of it cause i cut the rest just to post the image

Blacktea

unread,
Dec 7, 2015, 4:01:31 PM12/7/15
to MIT App Inventor Forum
I have tried with posttextwithencoding ... text the same, encoding utf-8 ... same result.

if i use GET without a text it gives back same result .... uhmm ...

Blacktea

unread,
Dec 8, 2015, 2:24:54 PM12/8/15
to MIT App Inventor Forum
Taifun i have resolved !!!!



it was just the "/" at the end of the address .... i have read it thousands of times and i get it only now :D

Thank you for help anyway!
Reply all
Reply to author
Forward
0 new messages