My goal is to give parameters to the webservice and get A specific JSON object but instead of that i am getting the whole JSON ARRAY with a lot of objects.I have some params that i need to set in order to get the specific object.
i have a code file in AngularJS -->
var webapihost = "http://192.168.0.6:81/ebswebapi/";
var scrollerid = "ES00BACKUP/KHCApp_Items"; // For our example, the View (scroller) ID that will be called
var scrid = "ES00BACKUP/KHCApp_Contacts";
var commandid = ""; // For our example, the Automation Command ID that will be called
var mastertableid = "";
var token = "";
/*********** DEMO ************/
$(document).ready(function () {
/*
Call login API
*/
$.ajax({
url: webapihost + "api/login",
type: "POST",
data: JSON.stringify({
/*
Following are the Credentials required to connect to the WebAPI server. Valiable model contains the credensial as they would be entered by an EBS user
*/
SubscriptionPassword: 'passx',
model: {
BranchID: "01",
LangID: "el-GR",
UserID: "khcadmin",
Password: "P@ssw0rd"
}
}),
contentType: "application/json; charset=utf-8",
success: function (result) {
token = result.Model.WebApiToken;
document.getElementById("token").innerText = token;
/*
After successfull loging in you may process with thw other calls, you have a valid token and you may proceed with other calls.
*/
GetScrollerData(token,scrid);
},
error: function (error) {
document.getElementById("token").innerText = "error:" + JSON.stringify(error);
console.log("error:" + JSON.stringify(error));
}
});
function GetScrollerData(token,scrid) {
/*
Call to get data from the View (scroller)
*/
$.ajax({
url: webapihost + "api/rpc/SimpleScrollerRootTable/" + scrid,
type: "GET",
headers: {
Authorization: 'Bearer ' + token
},
data: {
Code: "0013168"//Primary Key. If it does't exist it will create new person else it will update the data of the existing objects
},
contentType: "application/json; charset=utf-8", // returns JSON
success: function (srcresult) {
var data = JSON.stringify(srcresult);
document.getElementById("data").innerText = data;
if (data.length > 0 || typeof data != "undefined") {
}
},
error: function (error) {
document.getElementById("data").innerText = "error:" + JSON.stringify(error);
document.getElementById("data").innerText = "error:" + JSON.stringify(error);
console.log("error:" + JSON.stringify(error));
}
});
}
});
which works perfect
and i have also this code in Angular 5 which doesn’t work -->
import { HttpClient,HttpEvent,HttpClientModule } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import {Observable} from "rxjs/Observable";
import {Storage} from "@ionic/storage";
import {LoginscreenPage} from "../../pages/loginscreen/loginscreen";
import { HttpHeaders } from '@angular/common/http';
import {isSuccess} from "@angular/http/src/http_utils";
var webApihost="http://192.168.0.6:81/EBSWebApi/";
var scrollerid="ES00BACKUP/KHCApp_Items";
var scrid = "ES00BACKUP/KHCApp_Contacts";
@Injectable()
export class LoginserviceProvider {
public token:string;
params: {
SubscriptionPassword: string;
model: {
BranchID: string;
LangID: string;
UserID: string;
Password: string;
}
};
//scroller code below//
paramsScroller: {
headers: {
Authorization: string;
},
data: {
Code: string;
}
};
//scrid code below//
paramsScrid: {
type:string;
headers: {
Authorization: string;
},
data: {
Code: string;
},
contentType:string;
};
url = webApihost + 'api/login';
url2 = webApihost + "api/rpc/SimpleScrollerRootTable/" + scrollerid;
url3 = webApihost + "api/rpc/SimpleScrollerRootTable/" + scrid;
type;
constructor(public http: HttpClient,
private storage:Storage) {
console.log('Hello LoginserviceProvider Provider');
this.url =webApihost + 'api/login';
this.url2 =webApihost + "api/rpc/SimpleScrollerRootTable/" + scrollerid;
this.url3 =webApihost + "api/rpc/SimpleScrollerRootTable/" + scrid;
}
getWebApi(url, params) {
return this.http.post
(this.url, params);
}
getScrollerID(url, paramsScroller){
return this.http.get
(this.url2, paramsScroller);
}
getScrid(url, paramsScrid ){
return this.http.get
(this.url3, paramsScrid);
}
authenticationWebApi() {
this.url = webApihost + 'api/login';
this.params = {
SubscriptionPassword: 'passx',
model: {
BranchID: "01",
LangID: "el-GR",
UserID: "khcadmin",
Password: "P@ssw0rd"
}
};
console.log("Token Before = " + this.token);
return this.getWebApi(this.url, this.params)
.subscribe((data:any) => {
console.log(JSON.stringify(data));
this.token = data.Model.WebApiToken;
console.log(" Token -> " + this.token);
});
};
scrid() {
console.log("Entered into Scrid");
this.url = webApihost + "api/rpc/SimpleScrollerRootTable/" + scrid;
this.paramsScrid = {
type: "GET",
headers: {
Authorization: 'Bearer ' + this.token
},
data: {
Code: "0013168"
},
contentType: "application/json; charset=utf-8"
};
return this.getScrid(this.url,this.paramsScrid)
.subscribe((scrid:any) => {
console.log(JSON.stringify(scrid));
});
}
}