Yahoo Mail JSON API Invalid JSON - json

I am trying to use Java Scribe Library to integrate with Yahoo Web Service. I was able to get the OAuth Integration done.
Now I am trying to call the ListMessages JSON API using sample request in here http://developer.yahoo.com/mail/docs/user_guide/JSON-RPCEndpoint.html#
My code looks like this:
Token requestToken = buildTokenFromDB();
OAuthService service = new ServiceBuilder().provider(YahooApi.class).apiKey(API_KEY).apiSecret(API_SECRET).build();
OAuthRequest request = new OAuthRequest(Verb.GET,
"http://mail.yahooapis.com/ws/mail/v1.1/jsonrpc");
String str = getFilesAsString("msg.json");
request.addPayload(str);
request.addHeader("Content-Type", "application/json");
request.addHeader("Accept", "application/json");
service.signRequest(accessToken, request);
Response response = request.send();
I am getting the following error:
{"result":null,"error":{"code":"Client.InvalidRequest","message":"Invalid Json.","detail":null}}
Looks like I can only use GET, but I am not sure if I need to use some param for payload or scribe does it automatically.
Thanks.
Geeth

Related

SoapUI REST + JSON Mock Service: How can I return data from the request in a response?

I have a SoapUI REST (i.e. non-SOAP) mock service that returns a response for a POST request.
The request and response both contain JSON content.
At the moment, I can get it to return a static response and that works fine, but I want some of the values in the response to be dynamically sourced from the request.
So if I have this request:
{
"the_request":{
"abc":"123",
}
How can I get the value of "abc" copied in the response?
Investigation has lead me to believe I can do this via including a variable in the response, something like:
Response:
{
"the_response":{
"value_from_request":"${#MockResponse#Request#the_request#abc}",
"other":"stuff",
}
And then implementing a script to populate the variable in the response, via the Script tab.
How can I then populate this with data from the request?
Currently SoapUI just generates an empty value
"value_from_request":"",
Tried using mockRequest.requestContent in the Script tab, but have not found how to obtain the "123" value from it.
OK, worked this out. So the response message can simply reference a variable in the requestContext like so:
Response:
{
"the_response":{
"value_from_request":"${the_value}",
"other":"stuff",
}
And a groovy script can be used to parse the JSON request content and populate "the_value" or whatever you like in the requestContext:
// Parse the JSON request.
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
// Set up "the_value" from the request message.
requestContext.the_value = requestBody.the_request.abc
// Bit of logging so can see this in the "script log" tab.
log.info "Value extracted from request: ${requestContext.the_value}"
I think the script should be like this
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
context.setProperty("the_value",requestBody.the_request.abc)

WinRT use HttpClient to call Web API based URL with token

We are building a WinRT app which gets data from server which is Web API based & so it gives data in json and/or XML format.
When app user logs in for the first time using his credentials(username,password), the response that comes from server is a success bit & a TOKEN, which should be used in successive URL requests.
I am using httpclient for sending requests
using (HttpClient httpClient1 = new HttpClient())
{
string url = "http://example.com/abc/api/process1/GetLatestdata/10962f61-4865-4e7a-a121-3fdd968824b5?employeeid=6";
//The string 10962f61-4865-4e7a-a121-3fdd968824b5 is the token sent by the server
var response = await httpClient1.GetAsync(new Uri(url));
string content = await response.Content.ReadAsStringAsync();
}
Now the response that i get is with status code 401 "unauthorised".
And the xml i get in response is "Unauthorised User".
Is there anything i need to change in appManifest??
I've checked this, but cant we use httpclient without credentials??
Your Capabilities are enough. You don't even need Internet (Client) because it's included in Internet (Client & Server).
You do not have credentials for WinRT HttpClient, in your linked post they referr to System.Net.Http.HttpClientHandler.
Maybe you can use the HttpBaseProtocolFilter to add the credentials?
using (var httpFilter = new HttpBaseProtocolFilter())
{
using (var httpClient = new HttpClient(httpFilter))
{
httpFilter.ServerCredential...
}
}
I don't know your security mechanism, I'm using a HttpClient and my session-key is in a cookie. But I think your client code looks fine.

Json Webservice Call in Apex Salesforce

Can anyone share an end to end example for making a JSON webservice Call Through Apex ( Visual Force Pages and Controllers ) in Salesforce .
Pretty Much like we do in HTML5 ,Jquery by Ajax !
There are examples right in the documentation of calling REST web services.
From HTTP Classes:
public class HttpCalloutSample {
// Pass in the endpoint to be used using the string url
public String getContent(String url) {
// Instantiate a new http object
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
return res.getBody();
}
}
You can change the method to one of:
GET, POST, PUT, DELETE, TRACE, CONNECT, HEAD, and OPTIONS
A more complete example is available at HTTP (RESTful) Services
There is also support for JSON deserialization.
Don't forget to use the Remote Site Settings to open up access to the target domain.
For a SOAP web service you can define Apex classes from a WSDL.

NodeJS HttpGet to a URL with JSON response

I'm trying to make a server-side API call using a RESTful protocol with a JSON response. I've read up on both the API documentation and this SO post.
The API that I'm trying to pull from tracks busses and returns data in a JSON output. I'm confused on how to make a HTTP GET request with all parameters and options in the actual URL. The API and it's response can even be accessed through a browser or using the 'curl' command. http://developer.cumtd.com/api/v2.2/json/GetStop?key=d99803c970a04223998cabd90a741633&stop_id=it
How do I write Node server-side code to make GET requests to a resource with options in the URL and interpret the JSON response?
request is now deprecated. It is recommended you use an alternative:
native HTTP/S, const https = require('https');
node-fetch
axios
got
superagent
Stats comparision
Some code examples
Original answer:
The request module makes this really easy. Install request into your package from npm, and then you can make a get request.
var request = require("request")
var url = "http://developer.cumtd.com/api/v2.2/json/GetStop?" +
"key=d99803c970a04223998cabd90a741633" +
"&stop_id=it"
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body) // Print the json response
}
})
You can find documentation for request on npm: https://npmjs.org/package/request

How to get JSON from a WCF Data Services, DataServiceQuery call in Silverlight?

Background: I have a WCF Data Service with a Silverlight application that is currently using atom pub xml. I want to use JSON to lessen the size of the payload.
I read that you can JSON from the service webget using the following code:
WebClient wc = new WebClient();
wc.Headers["Accept"] = "application/json";
Can I modify the header for a DataServiceQuery call or a localContext.BeginExecute (for WebGets)?
// WCF Data Services Query Proxy
DataServiceQuery<T> query = filterExpression as DataServiceQuery<T>;
// Execute the ASYNC query against the model
query.BeginExecute(new AsyncCallback((iar) =>
{ ...});
or
// Create new context with the WCF service to force only save this entity
VisiconnEDM localContext = new VisiconnEDM(new Uri(entityServiceURL, UriKind.Absolute));
// execute the query asynchronously
localContext.BeginExecute<T>(urlQuery,(IAsyncResult iar) =>{ ...},null);
Even if you would modify the header for DataServiceRequest the client library of WCF DS doesn't have support for reading JSON responses, so it would not be able to read the response. The currently suggested approach to decrease the payload size is to use GZip.