I'm trying to use Open API in Vue.js.
When the webpage was created, i just wanna check the fetched data on console log.
This is the error image. enter image description here
And this is Network tab. enter image description here
code
created() {
const request = require("request");
const SERVIECE_KEY =" blah blah"; // secret
let url =
"https://cors-anywhere.herokuapp.com/http://openapi.molit.go.kr:8081/OpenAPI_ToolInstallPackage/service/rest/RTMSOBJSvc/getRTMSDataSvcAptTrade";
// use 'herokuapp' as a proxy server
let queryParams =
"?" +
encodeURIComponent("serviceKey") +
`=${SERVIECE_KEY}`;
queryParams +=
"&" +
encodeURIComponent("LAWD_CD") +
"=" +
encodeURIComponent("11110");
queryParams +=
"&" +
encodeURIComponent("DEAL_YMD") +
"=" +
encodeURIComponent("201512");
request(
{
url: url + queryParams,
method: "GET",
},
function (error, response, body) {
console.log("Status", response.statusCode);
console.log("Headers", JSON.stringify(response.headers));
console.log("Reponse received", body);
}
);
},
Try
The same request works on Postman with encoded service key (no proxy server URL).
it works on a browser as well.
Use decoded and encoded service key both above the code to check if the URL i entered is wrong
I know 403 error(forbidden) is due to the permission to access.
But i really don't know what could be the problem.
Related
I'm trying to debug another developers code which looks like this:
xhr.open("POST", url, true, this.state.userid, this.state.password);
xhr.withCredentials = true;
xhr.onload = () => {
console.log("here is our packet " + JSON.stringify(xhr));
if (xhr.status === 200) {
var test = xhr.getAllResponseHeaders();
var respoheader = JSON.stringify(xhr.responseHeaders);
var token = respoheader.substring(
respoheader.indexOf("LtpaToken2"),
respoheader.indexOf(
";",
respoheader.indexOf("LtpaToken2")
)
);
console.log("token is parsed ===" + token);
When I run this query from Postman I see two "Set-Cookie" headers added to the response, and one has the content "LtpaToken2=YpMnhu...", which is apparently what I need to grab. But when I run the code above, it does not include this header. I apparently need to grab this token for future calls to another API.
Can someone explain what I'm doing wrong? How can I capture this token, or how am I supposed to connect to another API without this token? As it seems to always be the case with IBM tech, I can find almost ZERO documentation about LtpaTokens.
On using the freshdesk api from google app script getting an error
"{"code":"invalid_content_type","message":"Content-Type header is set to . It should be set to application/json"}"
The code used for this
function hd_getTickets(){//using v2
var API_KEY = 'xxxxxxxxxxxxxx';
var headers = {'Content-type': 'application/json','Authorization': 'Basic ' + Utilities.base64Encode(API_KEY + ':X') };
var data = { "query":"\"priority:3\"" };
var ENDPOINT = 'https://xxxxxxx.freshdesk.com/api/v2';
var url = ENDPOINT + '/search/tickets';
var options = { 'method': 'get', muteHttpExceptions: true,'headers': headers,'payload' : JSON.stringify(data)};
var response = UrlFetchApp.fetch(url, options);
}
Changing the endpoint and removing the payload from options work so assuming authorization and header is fine
var url = ENDPOINT + '/tickets';
var options = {'method':'get','headers':headers, muteHttpExceptions: true};
Using postman this works
https://xxxxxxx.freshdesk.com/api/v2/search/tickets?query="priority:3"
with header set as
Content-Type:application/json
Authorization:Basic xxxxxxxxxxxxxxxx
You are sending a GET request to the API with the Payload variable in the options.
In my opinion payloads are used for POST requests.
Construct the URL with the query parameters and send it without the Payload.
Example: 'https://domain.freshdesk.com/api/v2/search/tickets?query="priority:3"'
See details here: HTTP GET with request body
Freshdesk API Doc: https://developers.freshdesk.com/api/#filter_tickets
Two issues found
1) web site does not support payload based get.
2) google apps doesn't support special characters in url.
Adding parameters to the original url and encoding the double quotes works.
var ENDPOINT = 'https://xxxxxx.freshdesk.com/api/v2';
var query ='query='+encodeURIComponent("\"priority")+":1"+encodeURIComponent("\"");
var url = ENDPOINT + '/search/tickets?'+query;
var options = {'method': 'get', muteHttpExceptions: true,'headers': headers};
var response = UrlFetchApp.fetch(url, options);
I'm attempting to set up a quick POC of an Autodesk Viewing App but I'm running into issues with authentication. I've already checked the following questions for general help but they're either covering extremely specific issues like HashTableMapping or haven't even been answered:
HTTP Status 415 - Unsupported Media Type when doing POST
HTTP status 415 when using Alamofire multipart upload
HTTP Error 500 when attempting to access localhost
The request failed with HTTP status 415
According to Autodesk's documentation my request structure is totally fine but seems to be throwing a 415 error. Anyone have any ideas or see something I'm not seeing? Here's my code below:
var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");
var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);
var headerRequest = "Content-Type: application/x-www-form-urlencoded";
var headerValue =
"client_id=_someSecretValue_" + "&" +
"client_secret=_someOtherSecretValue_" + "&" +
"grant_type=client_credentials" + "&" +
"scope=data:read";
xhr.setRequestHeader(headerRequest, headerValue);
xhr.send();
console.log(xhr.status); //getting a 415 here
console.log(xhr.statusText);
Got it - was my own faulty logic that screwed me up. The first request header wasn't formatted properly and I needed to send my information as a value:
var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");
var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);
//var headerRequest = "Content-Type:application/x-www-form-urlencoded";
var headerValue =
"client_id=_someSecretValue_" + "&" +
"client_secret=_otherSecretValue_" + "&" +
"grant_type=client_credentials" + "&" +
"scope=data:read";
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(headerValue);
console.log(xhr.status);
console.log(xhr.statusText);
I am trying to use Google Scripts UrlFetchApp to access a website with a basic username and password. As soon as I connect to the site a popup appears that requires authentication. I know the Login and Password, however I do not know how to pass them within the UrlFetchApp.
var response = UrlFetchApp.fetch("htp://00.000.000.000:0000/");
Logger.log(response.getContentText("UTF-8"));
Currently running that code returns "Access Denied". The above code does not contain the actual address I am connecting to for security reasons. A "t" is missing from all the "http" in the code examples because they are being detected as links and Stackoverflow does not allow me to submit more than two links.
How can I pass the Login and Password along with my request? Also is there anyway I can continue my session once I have logged in? Or will my next UrlFetchApp request be sent from another Google server requiring me to login again?
The goal here is to login to the website behind Googles network infrastructure so it can act as a proxy then I need to issue another UrlFetchApp request to the same address that would look something like this:
var response = UrlFetchApp.fetch("htp://00.000.000.000:0000/vuze/rpc?json={"method":"torrent-add","arguments":{"filename":"htp://vodo.net/media/torrents/anything.torrent","download-dir":"C:\\temp"}}");
Logger.log(response.getContentText("UTF-8"));
This question has been answered on another else where.
Here is the summary:
Bruce Mcpherson
basic authentication looks like this...
var options = {};
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
Lenny Cunningham
//Added Basic Authorization//////////////////////////////////////////////////////////////////////////////////////////
var USERNAME = PropertiesService.getScriptProperties().getProperty('username');
var PASSWORD = PropertiesService.getScriptProperties().getProperty('password');
var url = PropertiesService.getScriptProperties().getProperty('url');//////////////////////////Forwarded
Ports to WebRelay
var headers = {
"Authorization" : "Basic " + Utilities.base64Encode(USERNAME + ':' + PASSWORD)
};
var params = {
"method":"GET",
"headers":headers
};
var reponse = UrlFetchApp.fetch(url, params);
I was unable to find user3586062's source links (they may have been deleted), but taking Bruce Mcpherson's approach, your code would look like this:
var options = {};
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
UrlFetchApp.fetch("TARGET URL GOES HERE", options);
I am working with Titanium Studio and I have to make an HTTP get request to Couchdb. This is my code:
var url ="http://192.168.0.152:5985/hello_world/00a271787f89c0ef2e10e88a0c0001f4";
var json;
var xhr = Ti.Network.createHTTPClient({
onload: function() {
Ti.API.info("Received text: " + this.responseText);
json = JSON.parse(this.responseText);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
xhr.open("GET", url);
xhr.send();
The operation go in time out..
the code works fine. I tested it with a different URL.
first check the URL in a web browser to see how much it takes to load, then increase the timeout value.
if it works fine try opening the URL in the browser of the simulator, you may find that it's an IP problem
It is an ip problem in couchdb; couchdb server listen in 127.0.0.1.