Not getting the expected response from Backend in web service - javascript

I wrote an api call in AngularJS to get data from backend JAVA
Here is my code
$scope.memberForm = {};
$scope.memberForm.member_address = {};
$scope.memberRegForm = function() {
$scope.btnloading = true;
$('#add-btn').prop('disabled', true);
url = '/member/add';
var request = $http({
method: "post",
url: url,
data: angular.toJson($scope.memberForm),
headers: {
'Content-Type': 'application/json'
},
});
}
But I am not getting desire response from backed, Response that's I am actually getting from backend is
{
"fullname":"sdfgsdf",
"fathername":"sdfsdf",
"email":"sdfsdf#gmail.com",
"date_of_birth":"1993-03-24",
"admission_date":"2018-10-22",
"phoneno":"0987654321",
"nationality":"United States",
"member_address":
{
"address":"5 meadow st",
"state":"Connecticut",
"zipcode":"06770",
"district":"zc"
},
"college":"cvbcv",
"qualification":"bcvbcv",
"slno_ivpr":"12"
}
But here is my desire response. I need member_address as an array of ojects instead of a single object
{
"fullname": "avinash",
"fathername": "xxxxxxx",
"date_of_birth": "1991-08-08",
"nationality": "indian",
"admission_date": "2015-08-08",
"college": "ABC college",
"slno_ivpr": null,
"phoneno": "1234567890",
"email": "avinash.mitresource#gmail.com",
"remarks": "no remarks",
"member_renewal": [],
"qualification": "MCA",
"member_address": [
{
"address": "piratlanka,repalle",
"state": "AP",
"district": "Guntur",
"zipcode": "522264",
"type": "PermanentAddress"
},
{
"address": "padamata",
"state": "AP",
"district": "vijayawada",
"zipcode": "522201",
"type": "ResidencialAddress"
}
]
}

Related

Node.js paypal rest api error401

I am trying to create an invoice with Paypal rest API. I got an error
Error: Response Status : 401
Which is not saying more than that. I have double-checked my secret and id are correct and the mode is set to sandbox. I can't find anything wrong since I just copy-pasted in the example code to get started
Everything, making new client on PayPal developer portal. Just nothing makes sense anymore..
const config = require("../configs/bot_settings.json")
// PayPal //
const paypal = require('paypal-rest-sdk');
paypal.configure({
mode: config.paypal_mode, // Sandbox or live
client_id: config.paypal_id,
client_secret: config.paypal_secret
});
// PayPal //
var create_invoice_json = {
"merchant_info": {
"email": "PPX.DevNet-facilitator#gmail.com",
"first_name": "Dennis",
"last_name": "Doctor",
"business_name": "Medical Professionals, LLC",
"phone": {
"country_code": "001",
"national_number": "5032141716"
},
"address": {
"line1": "1234 Main St.",
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"country_code": "US"
}
},
"billing_info": [{
"email": "example#example.com"
}],
"items": [{
"name": "Sutures",
"quantity": 100.0,
"unit_price": {
"currency": "USD",
"value": 5
}
}],
"note": "Medical Invoice 16 Jul, 2013 PST",
"payment_term": {
"term_type": "NET_45"
},
"shipping_info": {
"first_name": "Sally",
"last_name": "Patient",
"business_name": "Not applicable",
"phone": {
"country_code": "001",
"national_number": "5039871234"
},
"address": {
"line1": "1234 Broad St.",
"city": "Portland",
"state": "OR",
"postal_code": "97216",
"country_code": "US"
}
},
"tax_inclusive": false,
"total_amount": {
"currency": "USD",
"value": "500.00"
}
};
paypal.invoice.create(create_invoice_json, function (error, invoice) {
if (error) {
throw error;
} else {
console.log("Create Invoice Response");
message.channel.send(invoice.total_amount)
console.log(invoice.total_amount);
}
});

trying to add user to database js

this code is used to add user to database
export const addUserInDB = (userEntityModel: UserEntityModel) => {
userEntityModel.id = '7';
return fetch(usersUrl, {
method: 'POST',
body: JSON.stringify(userEntityModel),
}).then((res) => res.json());
};
but it only returns this code in the database
{
"id": "Tcvpety"
}
And i want something like this
{
"id": "5",
"login": "luigi",
"password": "luigi125",
"email": "lluis.rubies#test.com",
"country": "Japan",
"type": "Customer",
"language": [
"Japanese",
"English"
]
},

How to display values in post { } in following example in vuejs?

{"status":true,"data":[{"agent_id":7042,"p_id":7039,"post":{"author":83,"created_on":"2017-10-07 14:28:36","sub_category":"Litigation Support","category":"Personal Investigation","budget":"5555","views":"0","status":"986","id":7039,"country":"India","state":"Kerala","quote":{"ref_id":"61","agent_id":7042,"p_id":7039,"created_on":"2017-10-09 10:41:15"}}},{"agent_id":7042,"p_id":7040,"post":{"author":83,"created_on":"2017-10-09 12:06:01","sub_category":"Pre-Matrimonial Investigation","category":"Personal Investigation","budget":"5555","views":"0","status":"984","id":7040,"country":"India","state":"Kerala","quote":{"ref_id":"61","agent_id":7042,"p_id":7039,"created_on":"2017-10-09 10:41:15"}}}]}
<div id="quotes">
<div v-for="post in data" class="mke_">
<card-component v-bind:id="post.p_id" v-bind:ins="post.category" v-bind:country="post.country" v-bind:state="post.state" v-bind:attachment_id="post.attachment_preview">
</card-component>
</div>
this is my vue js code to get the values, The values obtained is in the above format
quotes = new Vue({
'el' : '#quotes',
data : {
posts : [],
has_no_posts : true
},
mounted : function(){
var self = this;
$.ajax({
url : "url",
method : "POST",
dataType : "JSON",
data : {},
success : function(e){
if(e.status == true){
self.data = e.data;
if(e.data.length > 0)
self.has_no_posts = false;
}
}
});
}
});
This is my code to display the same which is getting error. So somebody please help me to didplay the same
You have to be more careful with your data.
First issue: you assign the result of your ajax query to self.data instead of self.posts.
Second issue: every "post" actually contains another "post" object with the actual post properties. So you need to use post.post.category to grab that.
See the below snippet. Note: I replaced your aja call with a setTimeout(0).
Finally, you should turn has_no_posts into a computed property that depends on self.posts.
var e = {
"status": true,
"data": [{
"agent_id": 7042,
"p_id": 7039,
"post": {
"author": 83,
"created_on": "2017-10-07 14:28:36",
"sub_category": "Litigation Support",
"category": "Personal Investigation",
"budget": "5555",
"views": "0",
"status": "986",
"id": 7039,
"country": "India",
"state": "Kerala",
"quote": {
"ref_id": "61",
"agent_id": 7042,
"p_id": 7039,
"created_on": "2017-10-09 10:41:15"
}
}
}, {
"agent_id": 7042,
"p_id": 7040,
"post": {
"author": 83,
"created_on": "2017-10-09 12:06:01",
"sub_category": "Pre-Matrimonial Investigation",
"category": "Personal Investigation",
"budget": "5555",
"views": "0",
"status": "984",
"id": 7040,
"country": "India",
"state": "Kerala",
"quote": {
"ref_id": "61",
"agent_id": 7042,
"p_id": 7039,
"created_on": "2017-10-09 10:41:15"
}
}
}]
};
new Vue({
el: '#quotes',
data: {
posts: [],
has_no_posts: true
},
mounted: function() {
var self = this;
setTimeout(function() {
self.posts = e.data;
self.has_no_posts = e.data.length > 0;
}, 0);
}
});
<script src="https://unpkg.com/vue"></script>
<div id="quotes">
<div v-for="post in posts" class="mke_">
<span v-bind:id="post.p_id">{{post.post.category}} - {{post.post.country}} - {{post.post.state}}</span>
</div>
</div>

JSON.PARSE without loosing header array field

function main(message){
...
phone= JSON.parse(message.phoneNumbers);
... }
My input JSON is
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
},
{
"type": "mobile",
"number": "123 456-7890"
}
],
"children": [],
"spouse": null
}
The result I receive is omitting the "phoneNumbers" but I do want it.
Your data is correct, when i JSON.parse it, i get everything allright.
But you don't seem to access to your data in the right way. You must first parse the whole JSON, then you have a javascript object, and only then you can acces your property.
in detail:
var obj = JSON.parse(message);
var phone = obj.phoneNumbers;
or in short:
var phone = (JSON.parse(message)).phoneNumbers;

How to make an AJAX call to GraphHopper Route Optimization API?

I'm trying to use GraphHopper Route Optimization API for solving VRP with pickups and deliveries. I want to test it with an example from https://graphhopper.com/dashboard/#/editor. My request goes like this:
var vrp = {
"vehicles": [
{
"vehicle_id": "my_vehicle",
"start_address": {
"location_id": "berlin",
"lon": 13.406,
"lat": 52.537
}
}
],
"services": [
{
"id": "hamburg",
"name": "visit_hamburg",
"address": {
"location_id": "hamburg",
"lon": 9.999,
"lat": 53.552
}
},
{
"id": "munich",
"name": "visit_munich",
"address": {
"location_id": "munich",
"lon": 11.57,
"lat": 48.145
}
},
{
"id": "cologne",
"name": "visit_cologne",
"address": {
"location_id": "cologne",
"lon": 6.957,
"lat": 50.936
}
},
{
"id": "frankfurt",
"name": "visit_frankfurt",
"address": {
"location_id": "frankfurt",
"lon": 8.67,
"lat": 50.109
}
}
]
};
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
},
type: "POST",
url: 'https://graphhopper.com/api/1/vrp/optimize?key=[...]',
data: vrp,
dataType: "json",
success: function(json){
console.log(json);
}});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I get the following response:
screenshot
Waht may be the problem here?
I'have found solution in another so-question Send JSON data with jQuery.
Just use data: JSON.stringify(vrp)

Categories