Yammer search V2 API - yammer

I.m trying to use Yammer V2 search endpoint but couldn't find any article that can help with CORS error. When I try V2 search, it just keeps giving CORS error however I'm able to use V1 search without any issue - so can you tell me what I'm doing wrong here ?
V1 search -
yam.platform.request(
{
url: "https://api.yammer.com/api/v1/search.json"
, method: "GET"
, data: { 'search': 'test'}
, success: function (msg) {
console.log('success');
}
, error: function (msg) { console.log("Error..." + msg); }
}
)
}
});
V2 Search -
yam.platform.request(
{
url: "https://www.yammer.com/api/v2/search/models"
, method: "GET"
, data: { 'search':'test', 'start':0, 'size':20, 'model_types':'threads',
'_network':5225275392, 'relevance':'DEFAULT'}
, success: function (msg) {
Display(msg);
}
, error: function (msg) { console.log("Error..." + msg); }
}
)
}
});

At the time of writing, this API is unsupported for use by external developers. The APIs under the V2 endpoint are primarily for first-party application use only. Support for searching is limited to the V1 endpoint. The supported APIs are listed in the main documentation.

Related

Access AWS Support Service using ajax

I'm trying to create a case using "create case" option using the AWS support service. I have a web application from which i want to create AWS support tickets. They only hurdle that is standing in my way is CORS (no surprises there :p) my question is, is there a way that i can create AWS support tickets (create case) by sending an ajax request to the end point? if yes, then how?
Do I need to enable the CORS support at the AWS end? how can i enable it?
what i have tried so far
$(function(){
$.getScript( "https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.41.0/aws-sdk.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
alert('loaded');
var support = new AWS.Support(options = {
endpoint :'END_POINT',
accessKeyId :'SOME KEY',
secretAccessKey :'YET ANOTHER KEY'
});
var params = {
communicationBody: 'STRING_VALUE', /* required */
subject: 'STRING_VALUE', /* required */
attachmentSetId: 'STRING_VALUE',
categoryCode: 'STRING_VALUE',
ccEmailAddresses: [
'STRING_VALUE',
/* more items */
],
issueType: 'STRING_VALUE',
language: 'STRING_VALUE',
serviceCode: 'STRING_VALUE',
severityCode: 'STRING_VALUE'
};
support.createCase(params, function(err, data) {
if (err){ // an error occurred
alert('error occured');
console.log(err, err.stack);
}
else {
alert('success');
console.log(data); // successful response
}
});
});//loadScript Ends
});//document ready ends
Any help in this regard is much appreciated.
Regards.
I am working on this also. The issue is that you need to include the build file for aws.support from here: https://sdk.amazonaws.com/builder/js/
At this time, I am able to download the js with the createCase, but not able to link it to the same example that you are doing. If the js is posted out to a web server, I am thinking that you can change the first line of code to point to that js file, but that is what I am working on now.

Parse Push's not delivered cloud code only

I'm running parse-server on ubuntu and can't seem to get push notifications working when sent in cloud code.
Push's work when using a REST api call (passing master key) but don't work when cloud code calls them.
What's interesting is that the cloud code Parse.Push() method returns a success and thus no error message.
My hypothesis is that this is a configuration problem, and the Parse.Push() method is referencing somethign I have incorrectly configured on the server.
here is my cloud function. This call works when sent via REST. and the success callback in cloud is always called.
Parse.Push.send(
{
// where: pushQueryClient,
channels: ["user_tkP7gurGzc"],
data:
{
alert: pushTextClient
}
},
{
success:function(){
console.log("push sent");
},
error: function(error){
console.log("push failed");
console.dir(error);
},
useMasterKey: true});
i think you have an issue with the useMasterKey parameter.
Please try to use this code in order to send the push notification:
Parse.Push.send({
where: whereQuery,
data: {
alert: {
title: request.params.title,
body: request.params.body
},
type: request.params.type,
sound: 'default'
}
}, {
useMasterKey: true
}).then(function() {
response.success();
}, function(error) {
response.error("Push failed " + error);
});
In this code i use Promises which is the best practice and also wrap useMasterKey in a separate object

How can i create a subscription plan on a connected account in Stripe?

I am trying to create a subscription plan on a stripe connect managed account. I tried the following code:
Parse.Cloud.define("createSubscription", function (request, response) {
Parse.Cloud.httpRequest({
method:"POST",
url: "https://" + "sk_test_****************" + ':#' + "api.stripe.com/v1" + "/accounts/" + 'acct_**********' + "/plans/",
headers: {
'Authorization': 'Basic ********************'
},
body: {
'amount': 2000,
'interval': 'month',
'name': 'JPGB Plan',
'currency': 'usd',
'id':'first Plan',
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code' + httpResponse.status);
}
});
});
But this failed with a 404 (the requested resource doesn't exist) error.
This is how I did it.
Parse.Cloud.define("createAccountPlan", function (request, response) {
Parse.Cloud.httpRequest({
method:"POST",
url: "https://" + "sk_test_****************" + ':#' + "api.stripe.com/v1/plans",
headers: {
'Stripe-Account': request.params.accountId
},
body: {
'amount': request.params.amount,
'interval': 'day',
'interval_count':request.params.intervalCount,
'name': request.params.planName,
'currency': 'usd',
'id':request.params.planId,
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code' + httpResponse.status);
}
});
});
What i think you should do is not to execute a direct http request to stripe REST API but to use strip node-js SDK that will do it and more for you.
In order to achieve it in parse server you need to do the following steps:
inside your parse-server project enter the following command
npm install stripe
this will install stripe into your parse-server project
In your cloud code require the stripe node SDK
var stripe = require('stripe')(' your stripe API key ');
Call to the create subscription function which available under the stripe object that you required
stripe.subscriptions.create({
customer: "{YOUR_CUSTOMER_ID}",
plan: "{PLAN_IDENTIFIER}"
}, function(err, subscription) {
// asynchronously called
}
);
Then if you need additional service call to stripe you can do it in the same way.
All the services that you can run with stripe can be found in here
It's always better to use SDK's when you can because SDK's make your
life much more easy, are handling all the things for you behind the
scenes and usually are maintained by the company who provided them (in
this case its stripe)
From the Stripe connect docs:
Authentication via the Stripe-Account header
The first, preferred, authentication option is to use your—the platform account’s—secret key and pass a Stripe-Account header identifying the connected account for which the request is being made.
(demo showing making a customer)
All of Stripe’s libraries support this style of authentication on a per-request basis
Stripe docs are a little subtle here, but this means you can use the same technique to make a subscription for a customer on a connected account. You can also use it to make the products and plans for that connected account too. and anything else you want to do on behalf of the connected customer:
(async function(){
let subscription = await stripe.subscriptions.create({
customer: "someCustomerID",
plan: "planID"
},{
stripe_account: "connectedStripeAccountID"
});
})();

Ajax request with CORS redirect fails in IE11

I'm trying to make an ajax request to a resource on the same domain. Under certain circumstances the request gets redirected(303) to an external resource. The external resource supports CORS.
In browsers like Chrome, Firefox or Safari the request succeeds.
In IE11 the request fails with error:
SCRIPT 7002: XMLHttpRequest: Network Error 0x4c7, The operation was canceled by the user
The ajax request is made with jQuery:
$.ajax({
url: "/data",
type: "POST",
dataType: "json",
contentType: "application/json;charset=UTF-8",
data: JSON.stringify({name: 'John Doe'})
}).done(function () {
console.log('succeeded');
}).fail(function () {
console.log('failed');
});
I've build a little example which demonstrates the problem. You could see the code here.
w/o redirect
w/ redirect
Is there a way to solve this problem? What am I missing?
In the initial definition of the CORS-standard, redirects after a successful CORS-preflight request were not allowed.
IE11 implements this (now outdated) standard.
Since August 2016, this has changed, and all major browsers now support it (Here's the actual pull request).
I'm afraid to support <=IE11 you'll have to modify your server-side code as well to not issue a redirect (at least for <=IE11).
Part 1) Server-side (I'm using node.js express here):
function _isIE (request) {
let userAgent = request.headers['user-agent']
return userAgent.indexOf("MSIE ") > 0 || userAgent.indexOf("Trident/") > 0
}
router.post('data', function (request, response) {
if (_isIE(request)) {
// perform action
res.set('Content-Type', 'text/plain')
return res.status(200).send(`${redirectionTarget}`)
} else {
// perform action
response.redirect(redirectionTarget)
}
})
Part 2 Client-side
Note: This is pure Javascript, but you can easily adapt it to your jQuery/ajax implementation.
var isInternetExplorer = (function () {
var ua = window.navigator.userAgent
return ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0
})()
function requestResource (link, successFn, forcedRedirect) {
var http
if (window.XMLHttpRequest) {
http = new XMLHttpRequest()
} else if (window.XDomainRequest) {
http = new XDomainRequest()
} else {
http = new ActiveXObject("Microsoft.XMLHTTP")
}
http.onreadystatechange = function () {
var OK = 200
if (http.readyState === XMLHttpRequest.DONE) {
if (http.status === OK && successFn) {
if (isInternetExplorer && !forcedRedirect) {
return requestResource(http.responseText, successFn, true)
} else {
successFn(http.responseText)
}
}
}
}
http.onerror = http.ontimeout = function () {
console.error('An error occured requesting '+link+' (code: '+http.status+'): '+http.responseText)
}
http.open('GET', link)
http.send(null)
}
its already answered - have a look - https://blogs.msdn.microsoft.com/webdev/2013/10/28/sending-a-cors-request-in-ie/

YouTube Data API: add a subscription

I'm using YouTube's V3 Data API to add a subscription to a channel. This occurs on a Wordpress installation.
I added Google APIs (for oauth) on Wordpress theme functions:
wp_enqueue_script( 'googleapi', 'https://apis.google.com/js/client.js?onload=googleApiClientReady', array(), '1.0.0', true );
I added in the same way the oauth javascript file, which is the first one here: https://developers.google.com/youtube/v3/code_samples/javascript.
Following this guide(https://developers.google.com/youtube/v3/docs/subscriptions/insert (Apps Script)), I extended the OAuth js with the addSubscription method.
Google Client API seems to be loaded and working as it calls correctly googleApiClientReady on the oauth javascript.
So, this is how the subscription is being inserted:
OAUTH JAVASCRIPT
... ... ...
// After the API loads
function handleAPILoaded() {
addSubscription();
}
function addSubscription() {
// Replace this channel ID with the channel ID you want to subscribe to
var channelId = 'this is filled with the channel ID';
var resource = {
snippet: {
resourceId: {
kind: 'youtube#channel',
channelId: channelId
}
}
};
try {
var response = YouTube.Subscriptions.insert(resource, 'snippet');
jQuery('#success').show();
} catch (e) {
if(e.message.match('subscriptionDuplicate')) {
jQuery('#success').show();
} else {
jQuery('#fail').show();
alert("Please send us a mail () with the following: ERROR: " + e.message);
}
}
So, the first error comes with
YouTube.Subscriptions.insert(resource, 'snippet')
It says YouTube is not defined. I replaced it with:
gapi.client.youtube.subscriptions.insert(resource, 'snippet');
And that error went away. When checking response, as the subscription isn't completed, this is what I get
{"wc":1,"hg":{"Ph":null,"hg":{"path":"/youtube/v3/subscriptions","method":"POST","params":{},"headers":{},"body":"snippet","root":"https://www.googleapis.com"},"wc":"auto"}}
So, I would like to know what's happening on that POST request and what's the solution to this.
I can post the full OAuth file, but it's just as in the example, plus that addSubscription method at the end.
Okay, I got it working, the problem was on the POST request. Here is the full method working:
// Subscribes the authorized user to the channel specified
function addSubscription(channelSub) {
var resource = {
part: 'id,snippet',
snippet: {
resourceId: {
kind: 'youtube#channel',
channelId: channelSub
}
}
};
var request = gapi.client.youtube.subscriptions.insert(resource);
request.execute(function (response) {
var result = response.result;
if (result) {
// alert("Subscription completed");
}
} else {
// alert("Subscripion failed");
// ...
}
});
}
Also make sure to load Google Apps API (in fact without it the authorize/login button won't work) and jQuery.
Any chance you can post everything that made this work...all the JS entire auth.js save for your private keys, im working on this exact problem.

Resources