How to get the JSON response from the Greenhopper REST API in Gadget? - json

I am not able to get the response from the GreenHopper REST API for the url http://:2990/jira/rest/greenhopper/1.0/sprints/1 through my Gadget application.
I able to get the following output when I try it from Browser, Below is the Output.
{"sprints":[{"id":1,"name":"Sprint 1","closed":false}],"rapidViewId":1}
My Code snippet to retrive the sprint details in Gadget is :
args: {
key: "sprints",
ajaxOptions: function () {
return {
url: "/rest/greenhopper/1.0/sprints/1",
};
}
}
Can anybody sugget me how to get the JSON Response from greenhopper REST API for a JIRA dashboard.
I am getting following Exception in Server:
[talledLocalContainer] at java.lang.Thread.run(Thread.java:662)
[talledLocalContainer] 2013-04-25 15:26:58,985 http-2990-11 ERROR admin 926x5323x1 dggnll 172.27.186.82 /rest/greenhopper/1.0/sprints/1
[common.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service
[talledLocalContainer] javax.ws.rs.WebApplicationException
[talledLocalContainer] at com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66)
[talledLocalContainer] at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)

That's the right URL so maybe the sprint doesn't exist or you don't have permission to view it? Also, try using the Developer Workbox add-on and the REST API browser to test these kind of methods.

Related

Postman: SyntaxError: Unexpected number in JSON at position 1 at JSON.parse

I am a beginner at web development and I am trying to use Postman to send a POST request to one of my application's APIs.
I am using the Next.JS framework to build my website.
Here is my API:
import type { NextApiRequest, NextApiResponse } from "next"
export default async (
req: NextApiRequest,
res: NextApiResponse,
) => {
const userData = JSON.parse(req.body)
res.status(200).json(userData)
}
I simplified my API until I caught the error, and I believe that it is related to the JSON.parse(req.body) line.
This is a print of the data that I used to test the API on Postman
I get the following error:
SyntaxError: Unexpected number in JSON at position 1
at JSON.parse (\u003canonymous\u003e)
at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/login.ts:9:27)
Previously, I used this API to authenticate users, and everything worked fine, except when I tried to insert data into the body of a Postman POST request.
Can someone help me? I have no idea what to do.
If you want to deserialize the body from a POST request, you also have to send a request where the body contains any data because otherwise, req.body will be null and that is not valid json.

ExpoAppAuth + Instagram Error: ExpoAppAuth.Get Auth: JSON deserialization error

just trying to receive access token from instagram api. I am using expo app-auth and running on android. My usage is straight from demo https://docs.expo.io/versions/latest/sdk/app-auth/#usage
Of course I changed config to:
let config = {
issuer: 'https://api.instagram.com/oauth/authorize',
scopes: ['user_profile', 'user_media'],
clientId: '33562202******'
};
And received that kind of error:
[Unhandled promise rejection: Error: ExpoAppAuth.Get Auth: JSON deserialization error]
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:99:50 in fn
- node_modules\#unimodules\react-native-adapter\build\NativeModulesProxy.js:15:41 in moduleName.methodInfo.name
- ... 9 more stack frames from framework internals
Any tips how to manage with that kind of error? I guess that maybe instagram returns data in format different than JSON but have no green idea how to read that data, because of throwing error.

VSCode JSON language server unhandled method

I posted this last week and have made progress since, where I've discovered the packages that VSCode's JSON support is delivered via extensions:
https://github.com/vscode-langservers/vscode-json-languageserver
https://github.com/Microsoft/vscode-json-languageservice
and all the rest. I'm trying to reuse this in an Electron (NodeJS) app. I'm able to fork a process starting the language server and initialize it:
lspProcess = child_process.fork("node_modules/vscode-json-languageserver/out/jsonServerMain.js", [ "--node-ipc" ]);
function initialize() {
send("initialize", {
rootPath: process.cwd(),
processId: process.pid,
capabilities: {
textDocument: true
}
});
}
lspProcess.on('message', function (json) {
console.log(json);
});
and I see that console.log firing and showing it seems to be up correctly.
My thoughts are that I just want to send a textDocument/didChange event as per the LSP:
send('textDocument/didChange', {
textDocument: TextDocument.create('foo://bar/file.json', 'json', 0, JSON.stringify(data))
});
where data is a JSON object representing a file.
When I send that message and other attempts at it I get
error: {code: -32601, message: "Unhandled method textDocument/didChange"}
id: 2
jsonrpc: "2.0"
Any idea what I'm doing wrong here? My main goal is to allow edits through my Electron app and then send the updated JSON to the language server to get schema validation done.
EDIT: I'm even seeing unhandled method initialized when I implement connection.onInitialized() in the jsonServerMain.js.
EDIT2: Update, I figured out where I was going wrong with some of this. initialized and textDocument/didChange are notifications, not requests.
EDIT2: Update, I figured out where I was going wrong with some of this. According to the LSP, initialized and textDocument/didChange are notifications, not requests. Requests have an id field that notifications don't, so when sending a notification, remove the ID field.

StackExchange API authentication in Google Apps Script

I'm trying to use the V2.2 of StackExchange API in Google Apps Script.
The problem comes in the last step of the explicit OAuth 2.0 flow, when I try to send the POST request to obtain the access token. I receive a 404 error, but making the same request manually (using postman extension) everything is ok.
To simplify the problem, if I send this POST request with no payload I receive the same 404
var response = UrlFetchApp.fetch("https://stackexchange.com/oauth/access_token", {
method: 'post',
muteHttpExceptions: true
});
Logger.log(response);
while in postman I receive this 400:
{
"error": {
"type": "invalid_request",
"message": "client_id not provided"
}
}
I guess this will be a problem with UrlFetchApp, but does anyone know how to solve it? Thanks!
The problem is related with the Origin header.
You cannot remove from the header directly but you can perform the call via a proxy :)
You need to provide the data for the post by adding an 'option' object to the call.
For example:
var options = { "method" : "post", "payload" : payload };
UrlFetchApp.fetch("https://stackexchange.com/oauth/access_token", options);
Btw, have you tried you use the OAuth that UrlFetch got: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#addOAuthService(String) - It might be better way.

Gson Syntax Exception causing Retrofit Error

I am in the process of connecting to a custom RESTful API using Retrofit. I have testing communicating with the device/API via Curl and with some test Java code running on a non-Android system (mac os x). The curl and java commands return the expected response.
However, using retrofit, I am unsure if I am using an inadequate configuration in my RestAdapter (i.e. RestAdapter.Builder()) to talk to this device.
The error I am getting appears to be that the entire json contents is not returned and only the first 47 bytes or so. I expect this is a behavior of the device I'm talking to, and am curious if this means I need to implement an Asynchronous callback as described in the Retrofit API docs. Before I do this I wanted to get feedback from some who have more experience with Retrofit.
The error is as follows (sanitized for public consumption):
12-06 08:50:52.962 28267-1735/com.mycompany.project D/Retrofit? [ 12-06 08:50:52.972 28267: 1735 D/Retrofit ]
{"OBJECT1":{"#Version":1,"OBJECTARRAY1":[
12-06 08:50:52.972 28267-1735/com.mycompany.project D/Retrofit? <--- END HTTP (46-byte body)
12-06 08:50:52.982 28267-1735/com.mycompany.project W/System.err retrofit.RetrofitError: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 47
I am setting up the RestAdapter as such:
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(serverUrl)
.setClient(new OkClient(RestUtils.getHttpClient(3000, 3000, username, password)))
.setRequestInterceptor(new RequestInterceptor() {
#Override
public void intercept(RequestFacade requestFacade) {
requestFacade.addHeader("Accept", "application/json");
requestFacade.addHeader("Client-Id", "12345");
}
})
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
service = restAdapter.create(OBJECT1.class);
Any insight into this problem would be greatly appreciated. I understand this error is related to the java.io.EOFException, but have been unable to verify the contents I am getting returned from the device, except for the output shown above in the error. I am heavily leaning towards the async vs. sync being the issue, but am open to any recommendations.
Cheers!