So I'm working a bit with nodeJS and Steam API to try and make a trade bot
I need to know what items was recieved, but when I do I get
undefined
Here's the JSON:
{
"partner":{
"universe":1,
"type":1,
"instance":1,
"accountid":369917733
},
"id":"2112720622",
"message":"No need to accept, just testing out a bot.",
"state":3,
"itemsToGive":[
],
"itemsToReceive":[
{
"appid":730,
"contextid":"2",
"assetid":"10168993563",
"classid":"1989300153",
"instanceid":"302028390",
"amount":1,
"missing":true,
"icon_url":"IzMF03bi9WpSBq-S-ekoE33L-iLqGFHVaU25ZzQNQcXdB2ozio1RrlIWFK3UfvMYB8UsvjiMXojflsZalyxSh31CIyHz2GZ-KuFpPsrTzBG0qe6yD3n-ZDLdYXKOTVxqTudcPGjZrGLx5ujCF2nASeh-EF9XdfEAo2JLNZiKahtv0oMVu2u_0UdyEhk6f9BKZAarxm1OMLh9m3IWGBD1M58",
"icon_url_large":"IzMF03bi9WpSBq-S-ekoE33L-iLqGFHVaU25ZzQNQcXdB2ozio1RrlIWFK3UfvMYB8UsvjiMXojflsZalyxSh31CIyHz2GZ-KuFpPsrTzBG0qe6yD3n-ZDLdEC3YDlltU-cLND7c92Hxt-SVFGqfFe54SgACdfcFoDJPP82AOBtrhdZZ-Ga9zhwzDhgvNMZJfACpx2EfJbQ1xDhPJM5amiekAf1NktA",
"icon_drag_url":"",
"name":"Sealed Graffiti | Still Happy (Desert Amber)",
"market_hash_name":"Sealed Graffiti | Still Happy (Desert Amber)",
"market_name":"Sealed Graffiti | Still Happy (Desert Amber)",
"name_color":"D2D2D2",
"background_color":"",
"type":"Base Grade Graffiti",
"tradable":true,
"marketable":true,
"commodity":true,
"market_tradable_restriction":7,
"fraudwarnings":[
],
"descriptions":[
{
"type":"html",
"value":"This is a sealed container of a graffiti pattern. Once this graffiti pattern is unsealed, it will provide you with enough charges to apply the graffiti pattern <b>50</b> times to the in-game world.",
"app_data":""
},
{
"type":"html",
"value":" ",
"app_data":""
},
{
"type":"html",
"value":"",
"color":"00a000",
"app_data":{
"limited":"1"
}
}
],
"owner_descriptions":[
],
"actions":[
{
"name":"Inspect in Game...",
"link":"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S%owner_steamid%A%assetid%D9253357711394385702"
}
],
"market_actions":{
"0":{
"name":"Inspect in Game...",
"link":"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9253357711394385702"
}
},
"tags":[
{
"internal_name":"CSGO_Type_Spray",
"name":"Graffiti",
"category":"Type",
"category_name":"Type"
},
{
"internal_name":"normal",
"name":"Normal",
"category":"Quality",
"category_name":"Category"
},
{
"internal_name":"Rarity_Common",
"name":"Base Grade",
"category":"Rarity",
"color":"b0c3d9",
"category_name":"Quality"
},
{
"internal_name":"Tint5",
"name":"Desert Amber",
"category":"SprayColorCategory",
"category_name":"Graffiti Color"
}
],
"id":"10168993563",
"owner_actions":[
],
"market_marketable_restriction":0
}
],
"isOurOffer":true,
"created":"2017-05-13T09:50:24.000Z",
"updated":"2017-05-13T09:50:48.000Z",
"expires":"2017-05-27T09:50:24.000Z",
"tradeID":"1915564581201455085",
"fromRealTimeTrade":false,
"confirmationMethod":0,
"escrowEnds":null,
"rawJson":"{\n\t\"tradeofferid\": \"2112720622\",\n\t\"accountid_other\": 369917733,\n\t\"message\": \"No need to accept, just testing out a bot.\",\n\t\"expiration_time\": 1495878624,\n\t\"trade_offer_state\": 3,\n\t\"items_to_receive\": [\n\t\t{\n\t\t\t\"appid\": \"730\",\n\t\t\t\"contextid\": \"2\",\n\t\t\t\"assetid\": \"10168993563\",\n\t\t\t\"classid\": \"1989300153\",\n\t\t\t\"instanceid\": \"302028390\",\n\t\t\t\"amount\": \"1\",\n\t\t\t\"missing\": true\n\t\t}\n\t],\n\t\"is_our_offer\": true,\n\t\"time_created\": 1494669024,\n\t\"time_updated\": 1494669048,\n\t\"tradeid\": \"1915564581201455085\",\n\t\"from_real_time_trade\": false,\n\t\"escrow_end_date\": 0,\n\t\"confirmation_method\": 0\n}"
}
I can easily get partner, id, message, state, isOurOffer and all the time things, but when I try to get itemsToRecieve, it just throws undefined
The JSON is gathered through an event and the above is the exact JSON that I recieved
This is the event:
manager.on('sentOfferChanged', function(offer, oldState) {
var state = offer.state;
if(state == 3) {
console.log("Offer " + offer.id + " was accepted");
console.log("[Offer #" + offer.id + "] The following items was recieved: ");
console.log(offer.itemsToReceive);
}
});
Why would it do that for only one of the objects?
Maybe you can use a for to log each item of itemToReceive.
Something like this:
manager.on('sentOfferChanged', function(offer, oldState) {
var state = offer.state;
if(state == 3) {
console.log("Offer " + offer.id + " was accepted");
console.log("[Offer #" + offer.id + "] The following items was recieved: ");
for(var i in itemstoReceive)
{
var name = itemsToReceive[i].name;
console.log(name);
}}
});
Related
I am attempting to query my database called battery2221 but keep getting no results. I've read all the API documentation but can't seem to find the problem. Any feedback is greatly appreciated. Here is my page code:
import wixData from 'wix-data';
$w.onReady(function () {
//TO DO: Write Your Page Related Code Here:
})
export function button1_click(event, $w) {
//Add your code for this event here:
getVINInfo($w("#vininput").value)
.then(VINInfo => {
console.log(VINInfo)
let year = VINInfo.Results[9].Value;
let make = VINInfo.Results[6].Value;
let model = VINInfo.Results[8].Value;
let engine = VINInfo.Results[71].Value + " " + "Liters"
let car = VINInfo.Results[9].Value + " " + VINInfo.Results[6].Value + " " + VINInfo.Results[8].Value;
wixData.query("battery2221")
.include("title")
.eq("year", year)
.eq("make", make)
.eq("model", model)
.find()
.then((results) => {
console.log(results);
$w("#results").text = "Vehicle Specific Battery for Your" + " " + car;
Here is what the developers console shows when I run the code:
_query:
{...}
jsonTableCopy JSON
orderBy:
"undefined"
invalidArguments:
[...]
filterTree:
{...}
jsonTableCopy JSON
$and:
Array(3)
jsonTableCopy JSON
0:
{...}
jsonTableCopy JSON
year:
"2019"
1:
{...}
jsonTableCopy JSON
make:
"HONDA"
2:
{...}
jsonTableCopy JSON
model:
"Civic"
{
"$and": [
{
"year": "2019"
},
{
"make": "HONDA"
},
{
"model": "Civic"
}
]
}
This code has worked when the Wix language was Corvid but since switching to Velo the code no longer functions.
What I need is to query the battery2221 database for the year, make and model from the VINInfo results. The result should be the battery reference field (field name is “title” in the database) from the database.
Any and all feedback is appreciated 😊
From my Laravel api I receive the following validation errors within json:
{
"error": {
"billabletime": [
"The billabletime field is required."
],
"time": [
"time bust be a integer."
]
}
}
So how would I show them in vue.js? Right now I've this but that's obviously not working:
showError (message) {
swal({
title: "Fout",
text: message.error,
type: "error",
timer: 2000,
showConfirmButton: false
});
}
Like this:
var errorString = '';
if (message.hasOwnProperty('error')) {
for(var prop in message.error) {
if (Array.isArray(prop)) {
for (var msg in prop) {
errorString += prop[msg] . '<br/>';
}
} else {
errorString += message.error[prop] . '<br/>';
}
}
}
Something simple like this should give you the desired result. Not necessary to know index names.
Edit added functionality to handle stirng/array
I need to output a count of items from JSON by category (using .length I believe), and would like to manage this in a controller so I can place it to scope anywhere I want. How can I filter REST JSON in a controller?
My sample JSON is as follows:
[
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D4",
"articletitle": "artilce1",
"articlecategoryid": 1,
"articlesummary": "article 1 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D5",
"articletitle": "artilce2",
"articlecategoryid": 2,
"articlesummary": "article 2 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D6",
"articletitle": "artilce3",
"articlecategoryid": 3,
"articlesummary": "article 3 summary. "
},
{
"id": "66D5069C-DC67-46FC-8A51-1F15A94216D7",
"articletitle": "artilce4",
"articlecategoryid": 1,
"articlesummary": "article 3 summary. "
},
]
My Resource is as follows:
// Articles by ID
pfcServices.factory('pfcArticles', ['$resource', function ($resource) {
return $resource('https://myrestcall.net/tables/articles', {},
{
'update': { method:'PATCH'}
});
}]);
My Controller is as follows:
// Count number of total articles
pfcControllers.controller('pfcArticleCountCtrl', ['$scope', 'pfcArticles', function ($scope, pfcArticles) {
$scope.articlecount = pfcArticles.query();
I believe I would need to add something to the controller (ex. $scope.cat1 = filter(my logic to get my category here), but am a little lost on how to query this so I have a count of items per category.
Build a filter like this.
angular.module('FilterModule', [])
.filter( 'cat1', function() {
return function(yourJSON) {
var count = 0;
yourJSON.forEach(function(item) {
switch(item.articlecategoryid) {
case 1:
count++;
break;
default:
console.log('item is not of category 1');
}
});
return count;
};
});
Inject the $filter service and fetch the cat1 filter. Now you can use it as $scope.cat1 = $filter('cat1')(yourJSON);
Please help me solve this. I'm new to node as well as json.
Something must have gone terribly wrong.
extends layout
block content
h3 Trips selection #{trips} //shows following json in the view
form.form-horizontal(id="Findtrips", accept-charset="UTF-8",
action="#", method="post" enctype="multipart/form-data")
each trip in trips
p #{trip.tripId} //doesnt pusblish anything
#{trips} gives following:
{
"onwardTrips": [{
"tripId": "1285170",
"fromCity": "Singapore",
"toCity": "Malacca",
"operatorCode": "SA",
"operatorName": "Starmart Express",
"departTime": "2014-01-20 20:00:00.0",
"busType": "Executive",
"pickupPointDetails": [{
"pickupPointId": "78",
"departureTime": "2014-01-20 20:00:00.0",
"pickupPointName": "Golden Mile Tower, Beach Road"
}],
"dropoffPointDetails": [{
"dropOffPointName": "Melaka Sentral",
"dropOffPointId": "1285170"
}],
"fareDetails": {
"adultFare": "65.0"
}
},
{
"tripId": "1285254",
"fromCity": "Singapore",
"toCity": "Malacca",
"operatorCode": "SA",
"operatorName": "Starmart Express",
"departTime": "2014-01-20 23:00:00.0",
"busType": "Executive",
"pickupPointDetails": [{
"pickupPointId": "78",
"departureTime": "2014-01-20 23:00:00.0",
"pickupPointName": "Golden Mile Tower, Beach Road"
}],
"dropoffPointDetails": [{
"dropOffPointName": "Melaka Sentral",
"dropOffPointId": "1285254"
}],
"fareDetails": {
"adultFare": "65.0"
}
}],
"errorCode": 0
}
server.js
getTrips: function getTrips(req, res, next){
var url = 'CTB-WS/rest/trips?from='+ req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date=' + req.tripinfo.departDate+ '&pax=1';
console.log(url);
rest.get(url).on('complete', function(trips) {
if (trips instanceof Error) {
console.log('Error:', trips.message);
} else {
console.log('trips'+ JSON.stringify(trips));
req.trips = JSON.stringify(trips);
next();
}
});
},
sendTrips: function sendTrips(req, res, next){
res.render('trips', {trips : req.trips});
}
In your json(actually Javascript object), trips is not an array. Instead trips.onwardTrips is an array.
Please change each in jade like
if trips.onwardTrips
each trip in trips.onwardTrips
p #{trip.tripId}
solved it by following. I got trips.tripId now I want to get array inside trip i.e. dropoffPointDetails.
getTrips: function getTrips(req, res, next){
var url = 'CTB-WS/rest/trips?from='+ req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date=' + req.tripinfo.departDate+ '&pax=1';
console.log(url);
rest.get(url).on('complete', function(trips) {
if (trips instanceof Error) {
console.log('Error:', trips.message);
} else {
console.log('trips'+ JSON.stringify(trips));
trips = trips || [];
req.trips = trips['onwardTrips'];
next();
}
});
},
sendTrips: function sendTrips(req, res, next){
//res.render('trips', {trips : req.trips});
res.render('trips', { trips: req.trips});
}
I have 3 functions that invoke a json response
function one gives:
{
"IT_INFO": {
"CARNET": "999250 ",
"CEDULA": "000013724224",
"NOMBRE": "pedro ",
"SEGNOMBRE": "salomon ",
"APELLIDO": "Perez ",
"SEGAPELLIDO": "Perza ",
"EMAIL": "mail#mailexample.com ",
"IAP": "0.00",
"IAA": "0.00"
}
}
second function :
{
"HISTORICOP": [
{
"MATERIA": "PROCESOS DEL LENGUAJE ",
"NOTA": "7 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "Ordinaria. Estado por defecto "
}
]
}
third function:
{
"HORARIO": [
{
"CODIGO": "BERSP01 ",
"MATERIA": " COMPUTADOR ",
"AULA": "A1-102 ",
"PROFESOR": "Quintero Moros, Nelson ",
"HORARIO": "TU WE FR 08:00-10:00 "
}
]
}
How should it come out so the function JSON.parse(str) will read it?
str = [func1,func2,func3] ??
or
str = [[func1],[func2],[func3]]?
or??? any ideas???
I assume you parse the JSON in JavaScript.
Normally you should not build JSON "manually", but in this case it does not seem to be too bad:
var objs = JSON.parse('[' + [func1(), func2(), func3()].join(',') + ']');
This creates a JSON array with the three objects returned by the functions.
Alternatively you can parse the responses individually:
var objs = [func1(), func2(), func3()];
for(var i = objs.length; i--; ) {
objs[i] = JSON.parse(objs[i]);
}
Of course you have to do things differently if the functions don't return the JSON but make some Ajax request...