Adding a social tag to a page - sharepoint-2010

In SharePoint when you click on the "I Like It" icon, it sends json to this URL
"_vti_bin/socialdatainternalservice.json/AddQuickTag"
So I wrote a custom script which sends JSON data
$("a").click(function(){
$.ajax({
type: "POST",
url: "/_vti_bin/socialdatainternalservice.json/AddQuickTag",
data: '{"targetPage":"http://url/calendar.aspx","title":"Documents - All Documents","quickTagId":0}',
contentType: "application/json",
success: function(msg){
alert(msg);
}
});
return false;
});
I get an error which simply says "There was an error processing the request." and the error in the log file says "Request format is unrecognized for URL unexpectedly ending in '/AddQuickTag'."
Is it possible to write a custom script which will post JSON data to this URL and have SharePoint tag a page?

These are the calls that are made for the I Like it functionality
/vti_bin/socialdatainternalservice.json/GetNormalizedPageUrl
Post
{"pageUrl":"http://<web app name>/SitePages/Home.aspx"}
Returned
{"d":"http://<web app name>/"}
/vti_bin/socialdatainternalservice.json/AddQuickTag
Post
{"targetPage":"http://<web app name>/","title":"Home - Home","quickTagId":0}
Returned
{"d":null}
I think you need to do the GetNormalized call first.

Related

API mocking in cypress intercept

I am new to cypress.
Problem: I am not able to intercept url for API mocking, when there are multiple APIs are appearing in console-> network tab
Description: My requirement is as follows:
login a website, after getting the landing page,go to a particular webpage, select multiple test cases check boxes
open console-> network tab , and click run
watch multiple APIs are coming
I selected one API url among them. I want to mock this particular one.
'GET'method , url (say: https://externalAPIurl) are copied in the following code
//verify landing page is reached
cy.contains("this is landing page").should("exist");
//after login open testcase page
cy.visit(
"https://example.com/testcases"
);
//go to test suite tab test suite
cy.get("#testsuiteid")
.click();
//click test suite name
cy.contains("testsuitename").click();
// select all test cases
cy.get(".testcasecheckbox")
.click();
cy.intercept(
{
method: "GET",
url: "https://externalAPIurl",
},
{
headers: {
authorization:
"AABBXXYY",
},
},
{
statusCode: 200,
body: [
{
status: 200,
result: true,
combination: [
//same data...
],
},
],
}
);
cy.get("#run_button").click();
});
Where am I wrong?
I checked in postman, the URL, with Get method and Header-> Authorization key with proper Authorization key value (as collected from network console Headers) giving correct response, but the cy.intercept is throwing error
How to solve this?
Whenever in a website we click a button, multiple external API s are visible in console-> network. If I take any one of them -> check the URL, method, header and getting the same response in postman as in the network console, I should be able to mock the same request URL.
I tried the same when one single API is appearing in network console. It was fine. But when I select one among multiple the result is an error.
Please note: I have included the header authorization, may be the format is wrong. But if I give or do not give the authorization, the result is the same error.
If you want to intercept a 'GET' and stub the response with predefined data. I would first use dev tools network tab to capture the api response you want. Copy the response and save as a json file in your fixture folder (you can edit this file as you see fit to fake the data how you wish). From there you can do the following:
cy.fixture('apiResponse.json').as('fixture data')
.then( (data) =>{
const raw = JSON.stringify(data)
cy.request( {
method : 'GET',
url : 'api url here',
headers : {
authorization : 'AABBXXYY',
},
body : raw
})
.then( (response) => {
cy.log(response.body)
expect(`Response.status = ${response.status}`).to.eq('Response.status = 200')
})
})

How to properly read POST params with express?

My node app is supposed to POST to an external server, so I'm playing with request from NPM. I want to verify it's working, but I'm not entirely sure I'm doing that right.
I've tried both of these methods
request({
url: url,
method: 'POST',
form: { a: 1}
}
request({
url: url,
method: 'POST',
json: true,
body: { a: 1}
}
In my test when I hit my own server, req.body shows the right object when I do json true. However that just means I'm passing a JSON header. The API I actually need to hit is expecting a normal POST, not JSON.
So when I try to verify that request is working right when I use form, my server says req.body is an empty object.
EDIT
I am posting to external API fine using form, but on my own server, express is leaving request.body as empty object.
See if this works for you:
request.post('http://service.com/upload').form({key:'value'})

Is it possible to post files to Slack using the incoming Webhook?

I am trying out the Slack's API using the incoming webhook feature, posting messages works flawlessly, but it doesn't seem to allow any file attachments.
Looking through I understand I have to use a completely different OAuth based API, but creating more tokens just for the purpose of uploading a file seems odd when posting messages works well, is there no way to upload files to slack with the incoming webook?
No, its is not possible to upload files through an incoming Webhook. But you can attach image URLs to your attachments with the image_url tag.
To upload files you need to use the Slack Web API and the files.upload method. Yes, it requires a different authentication, but its not that complicated if you just use a test token for all API calls.
You can see in the Slack API document that it's easy to add an attachment to the POST message to your webhook. Here is a simple example of sending a text message with an attachment in NodeJS:
import fetch from "node-fetch";
const webhook_url = "https://hooks.slack.com/services/xxxx/xxxx/xxxxxxxx"
const url = "https://1.bp.blogspot.com/-ld1w-xCN0nA/UDB2HIY55WI/AAAAAAAAPdA/ho23L6J3TBA/s1600/Cute+Kitten+13.jpg"
await fetch(webhook_url, {
method: "POST",
body: JSON.stringify({
type: "mrkdwn",
text: "Example text",
attachments: [
{
title_link: url,
text: "Your document: <file name>"
},
],
}),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});

Crossdomain jQuery ajax request was not called and give error status "parsererror"

I am trying to call cross domain url. which has response text as below.and it is valid json response.
[{"LANG_CODE":"UK_EN","COU_ISO_CODE":"BGR"},
{"LANG_CODE":"UK_EN","COU_ISO_CODE":"HUN"},
{"LANG_CODE":"UK_EN","COU_ISO_CODE":"PRT"},
{"LANG_CODE":"UK_EN","COU_ISO_CODE":"UGA"}]
Jquery ajax code which i am using for calling cross.
$.ajax({
url: "http://someDomainName/restfulservice/Api/Countries/Get_Json",
dataType: 'jsonp',
crossDomain: true,
async: false,
success: function (data) {
alert("success >> "+data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error : "+errorThrown + ", textStatus >> "+textStatus);
}
});
every time it goes to error block. when i inspect this service in browser then it gives response text with valid json string.but through code i am getting error "jQuery18305917718204907095_1409810925309 was not called, status: parsererror".
while this code is working for the url "http://api.geonames.org/findNearbyPlaceNameJSON?lat=47.3&lng=9&username=demo".
what could be the issue for same ?
It is sending back JSON but you have said dataType: 'jsonp'. JSON is not JSONP.
Either change the service to support JSONP or change the client to expect JSON (which might require you to find some other way to circumvent the same origin policy)

Callback not getting called on Internet Explorer for Ajax JSONP call

I'm making an Ajax call using JSONP to fetch JSON data from a third-party (domain different from my site) and its working on Chrome and Firefox but failing on IE (9 & 10 are the versions I have tried). In the IE debugger I see the call is completing (with Http 200) but the callback I've specified for the JSONP call is not being invoked.
My code looks like this:
$.ajax({
url: 'http://api.yipit.com/v1/deals/?key=mykey&division=seattle&limit=1000',
dataType: 'jsonp',
contentType: "text/javascript",
async: false,
cache: false,
crossDomain: true,
jsonp: 'callback',
jsonpCallback: 'processResult',
error: function (xhr, textStatus, error) {
window.alert(error);
},
success: function (data) {
window.alert(JSON.stringify(data));
_yipit_deals = data.response.deals;
}
});
And the response body looks like this:
<html><body><pre>processResult({
... [valid JSON data]
});</pre></body></html>
When the call is made, the error function is getting invoked with error as: Error: processResult was not called and the IE debugger shows a script error caused when trying to parse the <html><body><pre> tags in the response. When running on Chrome and Firefox these html tags don't exist in the response body and I'm not sure why the response is different in the case of IE.
It appears that these tags are causing IE to barf and not be able to invoke the callback. I've tried specifying other values for contentType such as "text/html", "text", "application/javascript" and even not specifying it at all, but its not made any difference. I'm using JSONP to get around the cross-domain issue.
Any ideas? Thanks!
You have to pass an explicit format argument to the URL:
&format=json
Otherwise, it's just pretty-printing the output:
<html><body><pre>{
"meta": {
"code": 401,
"message": "Key not recognized",
"name": "AuthenticationFailed"
},
"response": {}
}</pre></body></html>
Also, I would set async back to true.