So they have this JSON and i need specific items to get e.g. promotions:
{
"currency": "USD",
"code": 200,
"sales_list": [
{
"date": "2012-05-21",
"country": "JP",
units:{
app: {
downloads: 10,
updates: 1,
},
iap: {
sales: 3,
refunds: 5,
promotions:1
},
},
revenue: {
app: {
downloads “100.98”,
refunds: “-10.00”,
promotions: “1.00”
},
iap: {
sales: “30.00”,
refunds: “-1.00”,
},
ad: "1000.00"
},
}],
“iap_sales”:[
{
"date": "2012-05-21",
"country": "JP",
“iap”: “com.iap1”,
units:{
sales: 3,
refunds: 5,
},
revenue: {
sales: "30.09",
refunds: "1.21",
},
}],
"page_index": 1,
}
How do i get the to the promotions?
I tried to use this:
$json_data = connect(t_url);
$data = json_decode($json_data);
return $data->sales_list[0]->units[0]->app[0]->promotions;
but is it even effective/ efficient?
Also im having a hard time getting data from appannie. i always get authorization problem or bad request. If bad request it means im in though right?
I use the terminal to test curl and my url like:
curl --basic --user email : password "http:/www.appannie.com/v1/accounts/acntnum/..."
they suggested this since they have authentication. There are time i get bad request but i think im in unlike unauthorized access error.
They also suggest other forms like the authethication should be basic+base 64 of ur eadd and password. But I don't know where to use it.
Any suggestions to convert this into php curl request?
Related
I have a JSON data stream which contains a bunch of JSON objects prefixed with the 'Data: ' label. What is the simplest way to make this valid JSON so I can utilise the data stream in an application? The URL given is constantly updating so it has no end.
Short snippet of some of the streamed data:
data: {"value":12,"id":"window_doneTodayCount_1","updatedAt":1646316313574}
data: {"value":"4:30","id":"window_averageTime_1","updatedAt":1646316313596}
data: {"value":"Tue 11:05","id":"window_lastUpdatedTime","updatedAt":1646316313746}
I am looking to convert this dynamically to something like the below, which would be valid and I can use within an app:
[{
"value": 12,
"id": "window_doneTodayCount_1",
"updatedAt": 1646316313574
},
{
"value": "4:30",
"id": "window_averageTime_1",
"updatedAt": 1646316313596
}, {
"value": "Tue 11:05",
"id": "window_lastUpdatedTime",
"updatedAt": 1646316313746
}
]
Not even sure if this is possible as I have never seen a file like this.
Thanks.
I'm building a simple API based on Slim framework 3.8.1. I'm having an issue where the response is taking ~10 seconds to render. I've verified by process of elimination that it's the actual render of the response that's taking ~10 seconds--- it's not the database query, application bootstrap, etc.
I'm loggin the data I'm getting from the endpoint and it retrieves and renders it more or less instantly. The route actually even renders the JSON output right away in the browser, but then continues to spin for ~10,000ms.
Not sure what's going on here, especially since it's a pretty small set of data. Verified that this is happening in various browsers and also tests in REST clients like Postman.
I verified the middleware has long since executed when this waiting has happened, so that doesn't appear to be it.
Here's the minimal version of what I'm doing.
<?php
$api = new Slim();
$api->any('/{plant}/{noun}', function ($request, $response, $args) {
return $response->withStatus($status)->withJson(
$my_json
);
}
If I use ->write() and just send a short text string instead it's fine. If I pass JSON to ->write() it hangs the same, for ~10 seconds.
Oddly though if I do something simple like return $response->withStatus(404)->withJson(['foo'=>'bar']); it returns a response instantly, with the caveat that the response body is truncated and just shows {" instead of the full {"foo":"bar"} response I'm expecting.
Here's the JSON body I'm passing successfully but that renders for ~10 seconds:
{
"data": {
"id": "14",
"user_id": "1",
"name": "foozzz",
"description": "1q234567u12349",
"sku": "",
"price": "123.00",
"shipping": {
"r1-1": "123.00",
"r1-1+": "123.00",
"r2-1": "123.00",
"r2-1+": "123.00"
},
"flexible_price": "1",
"digital_fulfillment": "1",
"physical_fulfillment": "1",
"physical_weight": "0",
"physical_width": "0",
"physical_height": "0",
"physical_depth": "0",
"available_units": "-1",
"variable_pricing": "0",
"fulfillment_asset": "9",
"descriptive_asset": "64",
"creation_date": "1499186300",
"modification_date": "1499707715",
"variants": {
"attributes": [],
"quantities": [
{
"id": "13",
"key": "\"{\\\"123\\\":\\\"PURPLE\\\",\\\"2442\\\":\\\"djdoos\\\"}\"",
"formatted_name": "",
"value": "13"
},
{
"id": "14",
"key": "\"{\\\"123\\\":\\\"PURPLE\\\",\\\"2442\\\":\\\"dskmkdjjd\\\"}\"",
"formatted_name": "",
"value": "10"
},
{
"id": "15",
"key": "\"{\\\"123\\\":\\\"dappsajd\\\",\\\"2442\\\":\\\"djdoos\\\"}\"",
"formatted_name": "",
"value": "123"
},
{
"id": "16",
"key": "\"{\\\"123\\\":\\\"dappsajd\\\",\\\"2442\\\":\\\"dskmkdjjd\\\"}\"",
"formatted_name": "",
"value": "81"
}
]
}
},
"status": 200,
"status_uid": "commerce_item_200"
}
Originally I was thinking it was slow because of the size of the response, but this also takes ~10 seconds to finish loading (once again it renders instantly and then spins for the duration:
{
"status": 404,
"status_uid": "general_404",
"status_message": "Route not found, or server error",
"error_name": "There was an error while getting a response",
"error_message": "The request failed."
}
Running this on PHP 5.6.30 on Apache/2.2.15 with no other problems like this. Any thoughts of why this might be occurring?
Just to recap: it's taking ~10 seconds to load, but verified it's not the database or middleware. If I take out the return $response the page loads right away.
Any thoughts? Thanks!
Got it--- apparently Slim was adding a super long Content-Length header size to the $response and it was making the request take a lot longer to load.
I changed the initialization to this and it fixed the problem:
$api = new Slim(['settings' => [
'addContentLengthHeader' => false,
]]);
Confirmed that the full render + load time is now 113 ms instead of 10,000ms.
Thanks!
I have a query in aws cloudsearch. I did the following things
1) Created domain
2) uploaded the data & created indexing
I have data fields like : user_id, user_name, user_details, etc
My objective is to get the grouped/distinct data of particular field & its total count. In Cloudsearch Group by / Distinct key words not supported. So, I went through the cloudsearch documentation & done it by adding facet.user_id={} in my query string.
But I need user_name field data along with user_id and count.** Please update me regarding this.
Here is my full query : ?q="Tamil Selvan"&facet.user_id={}
Here is my query result :
{
"status": {
"rid": "isTcmOYp+AEKhpbc",
"time-ms": 6
},
"hits": {
"found": 986,
"start": 0,
"hit": []
},
"facets": {
"user_id": {
"buckets": [{
"value": "5",
"count": 213
}, {
"value": "182",
"count": 197
}]
}
}
}
My expected result :
{
"status": {
"rid": "isTcmOYp+AEKhpbc",
"time-ms": 6
},
"hits": {
"found": 986,
"start": 0,
"hit": []
},
"facets": {
"user_id": {
"buckets": [{
"value": "5",
"user_name":"Tamil Selvan",
"count": 213
}, {
"value": "182",
"user_name":"Tamil Selvi",
"count": 197
}]
}
}
}
The proper solution would be to look up the user_names for the user_id facet values from your datastore (which CloudSearch is not, or at least should not be).
CloudSearch is a search solution; you shouldn't be trying to ask it which user_name belongs to some user_id, as that's a question for your data store.
I am trying to integrate the bryntum component(schedule) in php. I am not much aware in ext js.
Please see the images here
Here, Name fields are fetching properly, whereas Capacity is not accessing. These values are coming from Zoho CRM.
My code is like Click, whereas r-read.php file is the responsible file for fetching the record from CRM and store it in a json format. It is like
{
"success": true,
"total": 9,
"root": [{
"Id": 1,
"Name": "Sri Test",
"Capicity": "190.0"
}, {
"Id": 2,
"Name": "tester_test01",
"Capicity": "500.0"
}, {
"Id": 3,
"Name": "Tesing room 23",
"Capicity": "5000.0"
}, {
"Id": 4,
"Name": "Test for 6th product",
"Capicity": "5000.0"
}, {
"Id": 5,
"Name": "Banquet hall test-01",
"Capicity": "500.0"
}, {
"Id": 6,
"Name": "test room",
"Capicity": "1000.0"
}, {
"Id": 7,
"Name": "Grande Ballroom",
"Capicity": "4000.0"
}, {
"Id": 8,
"Name": "Cedar Room",
"Capicity": "1400.0"
}, {
"Id": 9,
"Name": "Maple Room",
"Capicity": "1200.0"
}]
}
In the capacity column, it will show like 190.0 , 500.0, 5000.0 etc like Name column.
I'm not familier with the Bryntum schedular component, but most of the time when you have problems like these it's because you didn't define the Capacity field in your model.
I saw you used the following model: Sch.model.Resource. Can it be that is only has the Name field and not Capacity? Your JSON response looks fine to me.
In the sample JSON above, Capacity is spelled Capicity.
See if the same spelling needs can be used everywhere. Maybe then the data will resolve properly.
Recently, our team is going to develop mobile(iphone, android platforms) applications for our existing website, let user can use the application to more easy to read our content via the application.
But our team have different views in JSON schema of the API return, below are the sample response.
Schema type 1:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": {
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
"user": {
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": {
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
},
"user": {
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/2"
},
"post_ts": "2012-12-01 18:15:00T0800"
}
]
}
}
Schema type 2:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": 100,
"user": 1,
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": 101,
"user": 2,
"post_ts": "2012-12-01 18:15:00T0800"
}
],
"category": [
{
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
{
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
}
],
"user": [
{
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
{
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/Hello_baby"
}
]
}
}
Some Developers claim that if using schema type 2,
can reduce data size if the category & user entities comes too much duplicated. it does really reduce at least 20~40% size of response plain text.
once if the data size come less, in parsing it to JSON object, the memory get less
categoey & user can be store in hash-map, easy to reuse
reduce the overhead on retrieving data
I have no idea on it if schema type 2 does really enhanced. Because I read so many API documentation, never seen this type of schema design. For me, it looks like a relational database. So I have few questions, because I have no experience on designing a web services API.
Does it against API design principle (Easy to read, Easy to use) ?
Does it really get faster and get less memory resource on parsing on IOS / Android platform?
Does it can reduce the overhead between client & server?
Thanks you.
When I do such an application for android, I parse JSON just one and put it in database. Later I'm using ContentProvider to access it. In Your case You could use 2nd schema but without user, category part. Use lazy loading instead but it will be good solution just in case categories and users repeat often.