put call for host availabilities from google app script

114 views
Skip to first unread message

pavan

unread,
Jan 30, 2013, 1:18:00 PM1/30/13
to roomor...@googlegroups.com
Hi ,

I am trying to update the host avialability using roomarami apis in google app script. API is giving 401, I understand that some authorization problem but the same access token is working fine with GET calls.

My code:
function myFunction() {
  

  var headers = {
    "room_id" : "my_room_id",
    "date"  : "2013-08-01",
    "start_date" : "2013-01-04",
    "end_date" : "2013-01-06",
    "available": true,
    "nightly_rate":10,
    "weekly_rate" : 20,
    "monthly_rate" : 30,
    "can_checkin":true,
    "can_checkout":true,
    "format":"json"
    
    };
  
  var options = {
   
    "access_token":"my_access_token" ,
   
    "method" : "put",
    "headers":headers
    };
  var result = UrlFetchApp.fetch("api.roomorama.com/v1.0/host/rooms/my_room_id/availabilities.json",options);
  Browser.msgBox(result);
  

Can you please help?


pavan

unread,
Jan 30, 2013, 1:54:11 PM1/30/13
to roomor...@googlegroups.com
Hi,

Following is the complete code which am trying to access API, but am getting error "Exception: Unexpected error:".

Please help in resolving the issue.

function test() {
  var oAuthConfig = UrlFetchApp.addOAuthService("roomorama");
  oAuthConfig.setRequestTokenUrl("https://roomorama.com/oauth/authorize?response_type=token");
  oAuthConfig.setAuthorizationUrl("https://roomorama.com/oauth/authorize?response_type=code");
  oAuthConfig.setConsumerKey("xxxxxxxxxxxxxxxxx");
  oAuthConfig.setConsumerSecret("xxxxxxxxxxxxxxxxxx");
  
  var roomId = xxxx;  
  const apikey = "oQIcETvBBXEGAR0vNC0N715RkjAGV2ni2WAj1GMxUxI";
  
  var myDate = '2013-03-15';
  
  var params = {
      "method"       : "put", 
      "headers"      : {
        "date"         : myDate, 
        "nightly_rate" : 20
     },

    "oAuthServiceName" : "roomorama",
    "oAuthUseToken"    : "always"
  };
  
  try{
   var result = UrlFetchApp.fetch(URL,params);
   Browser.msgBox(result.getContentText());
  }
  catch(e){
    Browser.msgBox(e);
  }
}


Thanks,
Pavan

pavan

unread,
Jan 30, 2013, 10:36:00 PM1/30/13
to roomor...@googlegroups.com
Hello,

Can somebody please look into this and let me know, what's the problem here?

Thanks,
Pavan

Donald Piret

unread,
Jan 30, 2013, 11:10:10 PM1/30/13
to roomor...@googlegroups.com
Hello Pavan,

It looks like the format of the parameters you are sending through is invalid.
Please note that for post requests, the access token should be included in the request headers.

Please use our API documentation https://roomorama.com/api/documentation/v1.0 to check for the right format of the request and make sure yours corresponds.

To do so please head to the link above, fill in your access token at the top, then expand the Host/Availabilities -> Update section, fill in the parameters and press try-it. You will see a log of the call displayed. Make sure yours corresponds.

Please don't hesitate to let me know if you have any further issues in getting this to run.

Best,

Donald Piret

--
You received this message because you are subscribed to the Google Groups "Roomorama API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roomorama-ap...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Donald Piret

unread,
Jan 30, 2013, 11:19:26 PM1/30/13
to roomor...@googlegroups.com
Actually my bad, it seems IODocs doesn't display the request body and headers, but only the response body and headers. Will have to add that functionality.
It seems however that the format of the request you're sending through is invalid. Are you by any chance sending all parameters as headers?

Would you be able to provide a full trace of the request you're sending through?

Please make sure the auth token is sent as a header and your data is simple POST data.

pavan

unread,
Jan 30, 2013, 11:23:17 PM1/30/13
to roomor...@googlegroups.com
Hello Donald,

Thanks for your response. I've been trying with various options from last 24 hours but not succeeded. I'm writing this script in Google App Script. 

Can you please provide me a sample script correct way of doing?

I've attached the code that'm using in the update2.


Thanks,
Pavan

Donald Piret

unread,
Jan 30, 2013, 11:27:30 PM1/30/13
to roomor...@googlegroups.com
Hello Pavan,

Don't see any attachment. I'm not familiar with Google App Script so am not sure how much help I can be. Do you have any way of checking what request is being made to the server exactly? Looking at our log files it seems your parameters are not being recognised. I'm guessing you are passing all the data either as headers or query strings which is incorrect for a POST request.

Have you been able to get any of the other POST or PUT methods to work?

pavan

unread,
Jan 30, 2013, 11:38:51 PM1/30/13
to roomor...@googlegroups.com
Hi,

  var oAuthConfig = UrlFetchApp.addOAuthService("roomorama");
  oAuthConfig.setRequestTokenUrl("https://roomorama.com/oauth/authorize?response_type=token");
  oAuthConfig.setAuthorizationUrl("https://roomorama.com/oauth/authorize?response_type=code");

Can you please check and confirm are these URL's correct for oAuth? Or let me know correct URLs?

Thanks,
Pavan

Donald Piret

unread,
Jan 30, 2013, 11:42:19 PM1/30/13
to roomor...@googlegroups.com
Hello Pavan, these are the correct URL's

pavan

unread,
Jan 30, 2013, 11:50:01 PM1/30/13
to roomor...@googlegroups.com
Here's the complete code which'm using:

Am getting the following error: "
Exception: Unexpected error:"

Please check and let us know, what'm missing?

function test(){
  var oAuthConfig = UrlFetchApp.addOAuthService("roomorama");
  oAuthConfig.setRequestTokenUrl("https://roomorama.com/oauth/authorize?response_type=token");
  oAuthConfig.setAuthorizationUrl("https://roomorama.com/oauth/authorize?response_type=code");
  oAuthConfig.setConsumerKey("xxxxxxxxxxxxxxxxxxxxxxxxx");
  oAuthConfig.setConsumerSecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  
  var roomId = 74610;  
  const apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
  var par = {
    "method":"PUT",
    "headers"  : {
      "params[room_id]"    :"74610",
      "params[date]"       :"2013-01-31",
      "params[nightly_rate]":400,
      "access_token" : apikey,
      "apiSecret":"undefined",
      "apiName":"v1_0"
    },
    "oAuthServiceName" : "roomorama",
    "oAuthUseToken"    : "always"

  };
  
  
  try{
   var result1 = UrlFetchApp.fetch(url2,par);
   Browser.msgBox(result1.getContentText());
  }
  catch(e){
    Browser.msgBox(e);
  }
 
  return;
}

Donald Piret

unread,
Jan 31, 2013, 12:03:51 AM1/31/13
to roomor...@googlegroups.com
Hello Pavan, 

As I've just mentioned, it seems you are passing your parameters in the headers.

"headers"  : {
      "params[room_id]"    :"74610",
      "params[date]"       :"2013-01-31",
      "params[nightly_rate]":400,
      "access_token" : apikey,
      "apiSecret":"undefined",
      "apiName":"v1_0"
    },

DO NOT DO THIS

It seems you are using some kind of built-in facility of google app script to perform oAuth authentication? If this is the case I would direct your question as to how to correctly use this to their support group.

If you have your access token already you should be able to simplify your request to something like this:

var par = {
    "method":"put",
    "headers": {
      "Authorization"    :"Bearer SUBSTITUTETHISWITHYOURACCESSTOKEN",
    },
    "payload": {
      "start_date": "2013-01-31",
      "end_date": "2013-01-31",
      "nightly_rate":400
    }

  };
UrlFetchApp.fetch(url,par);

Namrata Patel

unread,
Jun 9, 2015, 10:34:10 AM6/9/15
to roomor...@googlegroups.com
Hello,

Ages later.. I am trying to do similar room post using python. My param are url-encoded in body and in the format mentioned above. Headers have accesstoken and content length

Also my test work from https://www.roomorama.com/api/v1_0 , and not from script. It keeps giving me 400 response code with no message body.
Any reason why it wont give me error message? 

Garima Singh

unread,
Jun 10, 2015, 1:48:38 AM6/10/15
to roomor...@googlegroups.com
Hello,

I am Using Roomorama API in one of my application.
Using it for list price/availability update through python script.
Test work on https://www.roomorama.com/api/v1_0 but not from the python script. It keeps giving me 400 response code with no message body.
I would appreciate your help in this matter.
Any reason why it wont give me error message?

Below given are the request options which i use:

REQUEST HEADERS:
{
    'Content-Length': '200',
    'Authorization': 'Bearer HEpxSOVKoCGK6UcqRi0O4tnCISumY64pJIAfGqz1Ks',
    'Content-Type': 'application/x-www-form-urlencoded'
}

REQUEST BODY:
available=true&end_date=2015-07-02&format=json&nightly_rate=190&weekly_rate=1330&can_checkin=true&date=2015-07-01&can_checkout=true&monthly_rate=5700&
room_id=354652&start_date=2015-07-01

REQUEST METHOD: PUT

REQUEST URL: https://api.roomorama.com/v1.0/host/rooms/354652/availabilities.json

Also request body which I send is url encoded format.

Is there anything I missed? I await a response at your earliest convenience.
Thanks in advance.

Reply all
Reply to author
Forward
0 new messages