Data not being formatted as JSON - ruby-on-rails-3

I am doing the following in a Facebook Request:
function sendRequests() {
FB.ui({
method: 'apprequests',
message: "You are invited to the surprise Birthday",
data:{"board_id":<%=#board.id%>}
When I get the request object from the user who accepted the application I parse it as a JSON object as follows:
ActiveSupport::JSON.decode(request_body.body)
All of the information is formatted as a Hash should in Rails except for the data I sent in which looks as follows:
"data"=>"{\"board_id\":1}"
I have tried all kinds of combinations but it just won't convert properly. Am I missing something or does the JSON returned by the facebook graph api need to be formatted differently?

Try copying the data and validating it manually here: http://jsonlint.com/
It has helped me numerous times.

In the end I did the following:
In the facebook fb.ui
FB.ui({
method: 'apprequests',
exclude_ids: <%=#invited_guests.map{|guest| guest.provider_user_id} %>,
message: <%="'You are invited to the surprise Birthday board for #{#board.bp_name}'" %>,
title: "Come celebrate with us",
data: "board_id:<%=#board.id%>"
Then in the controller after the request is accepted in facebook:
request_content = ActiveSupport::JSON.decode(request_body.body)
board = ActiveSupport::JSON.decode(request_content["data"])
I have to decode twice. Once for the whole request and the second time for the specific data information passed. It might not be pretty but it works.

Related

Getting RapidAPI to work with GoogleSheets to extract IMDB data

Google Sheets with RapidAPI
First time trying to get APIs to work! I thought a simple project would be to get a Googlesheet to retrieve movie information based on the title.
Googling around I happened upon RapidAPI which has a Googlesheets add-on. Unfortunately I haven't found much useful documentation so have hit a dead end.
What I've learned so far
There only seems to be one example for how to implement it... by using the =GET() command like so (in this case for pulling finance info):
=GET(”https://investors-exchange-iex-trading.p.rapidapi.com/stock/{symbol}/book”,”quote.companyName”,”YOUR_API_KEY_HERE”,”symbol”,”AAPL”)
I couldn't get this example to work, and the IMDB Code Snippet seems a little different, so I'm not sure how that works at all. Not the curly bracers around {symbol}.
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://imdb8.p.rapidapi.com/title/find',
params: {q: 'Dredd'},
headers: {
'x-rapidapi-host': 'imdb8.p.rapidapi.com',
'x-rapidapi-key': '5840855726msh193dee7e1600046p145eddjsnc66aff778896'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
When I run a typical search on IMDB, I get a URL that looks like this:
https://www.imdb.com/find?q=dredd&ref_=nv_sr_sm
I notice this q parameter there, which seems important...
I'm not sure how I am meant to format this =GET() command for IMDB data. The example suggests one thing, but Googlesheets suggests another: "GET(url, selectPaths, rapidApiKey)"
I'm not sure what the curly bracers are doing in the example URL.
Whatever I try seems to give the same error message:
Error
Request failed for https://imdb8.p.rapidapi.com returned code 400. Truncated server response: 400 - Bad Request (use muteHttpExceptions option to examine full response) (line 98).
Send Help
Does anyone have a better, working tutorial for using this setup? Or could you direct me to some useful reading material that a layperson could understand?
I found a good resource for you. Check out this well-written article on RapidAPI's official blog.
https://rapidapi.com/blog/api-google-sheets/

Are there examples of itineraries that are compatible with the Amadeus self-service trip parse API?

I've tried booking references from a dozen providers (which I don't want to post for privacy reasons) and every time the API returns 'Unable to parse' but with no additional diagnostic information.
As a self-service API they don't offer support through any channel other than Stack Overflow, but I'm hoping someone has successfully used the endpoint.
I'm mostly using GMail to access sample flight booking emails, then selecting "View Original" to download the original MIME format email
This is what I use to read the .eml file into code:
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(bitmap).toString('base64');
}
However every single email I submit to the endpoint eventually returns:
data:
{ data:
{ type: 'trip-parser-job',
id: 'REDACTED',
self: [Object],
status: 'ERROR',
detail: 'Unable to parse' } } }
and at this point, I'm starting to think that either the API is broken, or they haven't correctly documented what data should be submitted as content. I've decoded the sample document they provide and can't see any major difference between that and my inputs.
Does someone have either some working samples that the API was able to process, or some NodeJS code which seems to reliably get a result from the API?

How to get AWS API Gateway to validate JSON Body against Model

The newly released "x-amazon-apigateway-request-validator" (in April I believe) is supposed to be able to run a JSON schema validation against the POST/PUT payload of an API.
I've tried to implement this in several different ways now but I can't make it work...
I have added the validators:
"x-amazon-apigateway-request-validators": {
"ValidateBody": {
"validateRequestParameters": false,
"validateRequestBody": true
},
"ValidateHeaders": {
"validateRequestParameters": true,
"validateRequestBody": false
}
}
For any methind I will look for specific headers so I also have the parameters in the "root" of the Swagger:
"x-amazon-apigateway-request-validator": "ValidateHeaders"
In the POST I have a x-amazon-apigateway-request-validator: ValidateBody and then a Model with the JSON schema where several elements are required.
I can however POST anything as long as it is JSON... There is no validation against the JSON schema done...
What am I missing?
It is working!
There is a time lag between the deploy and the actual usage of the new code even though I am not doing any caching it seems.
Went out for lunch and came back to a working solution!
{
"message": "Invalid request body"
}
It would be nice to be able to modify the response message though...

Outpan API C# POST Request

What does the Outpan server expect when posting data?
GET was giving me a json info that I was able to convert to an object.
Now when I'm giving information back just like the name:
https://api.outpan.com/v2/products/UPCCode/name?apikey=xxx
it will always not understand my information (error 400). Already tried sending the json back with additional info, "Foodname" and "name = Foodname"

Unable to receive recipient view url of docusign

I am using docusign_rest gem. I am creating template with
create_template
method and envelope with
create_envelope_from_template
method.
But when I was trying to retrieving the url for embedded signing with the help of following code
client = DocusignRest::Client.new
#url = client.get_recipient_view(
envelope_id: #envelope_response["envelopeId"],
name: 'some_name',
email: 'some_email',
return_url: 'http://google.com'
)
then it returning nil. So I am unable to generate url.
When I am using the iodocs portal of docusign for the same POST request
Recipient v2/accounts/:accountId/envelopes/:envelopeId/views/recipient
{
"authenticationMethod": "email",
"email": "some_email",
"returnUrl": "www.gmail.com",
"userName": "some_name",
"clientUserId": "some_email"
}
I get the url as required.
So am I doing something incorrect in the ruby gem's call or is there a bug?
user2593706 : this will return nil because u r not passing any value #envelope_response["envelopeId"] so u need to pass the envelope id which is created previously or any other u want to get response. in rails its very easy to implement... if u want to look at response from docusign u need to use your terminal for that.. do this...
1. rails c
2. paste your create_template method code as yours
3. paste your create_envelope_from_template code
4. then run immediately your code
client = DocusignRest::Client.new
#url = client.get_recipient_view(
envelope_id: #envelope_response["envelopeId"],
name: 'some_name',
email: 'some_email',
return_url: 'http://google.com'
)
then u will get ur response.... hope this works. and its really good to do this task
To use embedding functionality for a given envelope, you need to set the clientUserId property at the time the envelope is being created, then you reference it again with the same value when requesting the URL (just like you have in your code).
This page from the DocuSign Dev Center explains it in more detail:
http://www.docusign.com/developer-center/explore/features/embedding-docusign