Uploading data from matlab to firebase - json

Firebase creates a name for the data i upload from matlab.
is there a way to cancel this name? or set it to something constant so the next time i upload ill overwrite it?
Example:
https://cdn1.imggmi.com/uploads/2019/3/24/0cb9e3c19155a8b338806121aed42ea2-full.jpg
(i want the data from matlab to be the same structure like the adc sample)
This is the code I use:
Firebase_Url = 'https://***.firebaseio.com/data_from_matlab.json/';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')

It looks like Matlab's webwrite function sends a HTTP POST request, which Firebase's REST API translates to create a new node with a new unique ID.
It looks like you can pass RequestMethod: 'put' in the weboptions parameter to send a PUT request, which Firebase translation to a direct write at the location. So something like:
webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }',
weboptions("RequestMethod", "put"))

I actually was having a similar problem but I wanted to add multiple objects with different names and when I used RequestMethod: 'put' in weboptions Firebase deleted my old objects. I looked into the link given above I discovered that using RequestMethod: 'patch' I could add multiple objects under the same category without getting the randomly generated key.

Related

User Titles in Firebase Realtime Database

so I am importing a JSON file of (Example) Users into Realtime Database and have noticed a slight issue.
When added, each User is sorted by the number order they are in on the JSON File. Since it starts with User 4, it has the value of 1. As seen here:
.
The User Json is formatted as such:
{
"instagram": "null",
"invited_by_user_profile": "null",
"name": "Rohan Seth",
"num_followers": 4187268,
"num_following": 599,
"photo_url": "https://clubhouseprod.s3.amazonaws.com:443/4_b471abef-7c14-43af-999a-6ecd1dd1709c",
"time_created": "2020-03-17T07:51:28.085566+00:00",
"twitter": "rohanseth",
"user_id": 4,
"username": "rohan"
}
Is there some easy way to make it so the titles in Firebase are the User ID's of each user instead of the numbers currently used?
When you import a JSON into the Firebase Realtime Database, it uses whatever keys exist in the JSON. There is no support to remap the keys during the import.
But of course you can do this with some code:
For example, you can change the JSON before you import it, to have the keys you want.
You can read the JSON in a small script, and then insert the data into Firebase through its API.
I'd recommend against using sequential numeric IDs as keys though. To learn why, have a look at this blog post: Best Practices: Arrays in Firebase..

Automatically run the same request for every id in a JSON file in Postman

I would like to have Postman automatically make the same delete API call for all of the Ids listed in a JSON file since the API I am using does not allow multi-delete.
Something like:
http://testing.com/api/product/{{Id}}
I have a list of ids in the following json format:
[{
"name": "Prod 1",
"id": 14324
},
{
"name": "Prod 2",
"id": 32424
},
{
"name": "Prod 3",
"id": 45645
}]
How can I go about running something that will run the same request for every id in the JSON list?
Yes that is possible using the Collection Runner. An explanation can be found in the documentation: Working with data files
In short:
Store your JSON into a .json file.
Make sure your request is part of a collection.
Add the JSON property key (id in your case) as a variable to your URL like you did in your example URL: http://testing.com/api/product/{{id}}
(Make sure the casing of the variable matches the one in your JSON file.)
Click on the "Runner" button in the top left of Postman to open the Collection Runner.
On the left select the collection and on the right check the request you want to run.
Click on the "Select File" after the "Data" option and select your JSON file.
Hit "Preview" below to see if the JSON is interpreted correctly.
At the "Iterations" option enter the number of objects you have in your JSON.
(In your sample that would be 3)
Hit "Run [Collection name]".
At that point Postman should repeat the request for the amount entered in the "Iterations" option and for each iteration replace your {{id}} in the URL with the id in your JSON for that iteration.

Structuring json data in GET call query parameters

I'm trying to pass a list of the following objects as query params to a GET call to my Java service:
{
"id": "123456",
"country": "US",
"locale": "en_us"
}
As a url, this would like like
GET endpoint.com/entity?id1=123456&country1=US&locale1=en_us&id2=...
What's the best way to handle this as a service? If I'm passing potentially 15 of these objects, is there a concise way to take in these parameters and convert them to Java objects on the server side?
I imagine with a URL like this, the service controller would have a lot of #QueryParams...
Create the entire dataset as JSON array, e.g.
[
{
"id": "123456",
"country": "US",
"locale": "en_us"
},
{
"id": "7890",
"country": "UK",
"locale": "en_gb"
}
]
base64 encode it and pass it as a parameter, e.g.
GET endpoint.com/entity?set=BASE64_ENCODED_DATASET
then decode on the server and parse the JSON array into Java objects using perhaps Spring Boot.
Based on the valid URL size comment (although 2000 is usable), you could put the data in a header instead, which can be from 8-16kb depending on the server. GETting multiple resources at once is going to involve compromise somewhere in the design.
As Base64 can contain +/= you can url encode it too although I haven't found the need to do this in practice when using this technique in SAML.
Another approach would be to compromise on searching via country and locale specific IDs:
GET endpoint.com/entity/{country}/{locale}/{id_csv}
so you would search like this:
GET endpoint.com/entity/US/en_us/123456,0349,23421
your backend handles (if using Spring) as #PathParam for {country} and {locale} and it splits {id_csv} to get the list of IDs for that country/locale combination.
To get another country/locale search:
GET endpoint.com/entity/UK/en_gb/7890,234,123232
URLs are much smaller but you can't query the entire dataset in one go as you need to query based on country/locale each time.
It looks like your GET is getting multiple resources from the server. I'd consider refactoring to GET 1 resource from the server per GET request. If this causes performance issues, consider using HTTP caching.

Need to extract JSON data from a JMeter response?

In JMeter, I need to extract some fields (City, Classification, and Chain) from a JSON response:
{
"StoreCode": "111243",
"StoreName": "Spencer - Sec 14 Gurgaon",
"Address1": "Gurgaon-Sector-14",
"Address2": "NCR",
"Pin": "110000",
"City": "NCR",
"Classification": "Vol 4",
"Chain": "Spencers",
"Version": "20281",
"VisitType": "Weekly"
}
Can it be done using the regular expression extractor? Is there another option?
If this piece of JSON is the all the response - it makes sense to use Regular Expression Extractor.
If you receive larger or more complicated structure - it's better to use special JSON Path Extractor available through plugin. JSON Path expressions for your JSON response would be something like $.City, $.Chain, etc.
See "Parsing JSON" chapter of Using the XPath Extractor in JMeter guide for more details on JSON Path language and on how to install the plugin.
Very easy with the plugin mentioned. See this for example. Here is link to plugin.
My biggest thing to understand was the flow. In your jmeter test you need to have an httprequest that returns data (in this case json data). So running your test you'd see json in the Response Data tab if you have a View Results Tree listener going. If you have this right click on the HttpRequest you want data from. ADD => Post Processors => jp#gc - JSON Path Extractor. Inside that extractor, you can name it anything you want.
The variable name should be one you already have defined in a User Defined Variables config element. The JSON Path would start with a dollar sign, then a dot, then the name of the key you want the value for from your json. So for me: $.logId the value from ... "logId": 4, ... in my json. It will store the number 4 in my userdefined variable. The default value can be set to something you'd never see like -1 or null or false etc...
BTW you reference your variable in your tests with ${variablename}. If putting into json and its a string do "${variablename}". Hope it helps.
Lots of the way to find out with the help of regular expression. Sharing one of them.
"City": "(.*)",
"Classification": "(.*)",
"Chain": "(.*)",

Wrapping JSON payload with key in EmberJS

Ok basically I am sending a POST request with some JSON payload in it to Codeigniter. I use RESTAdapater. JSON get sent there with no key, so I have no access to it.
Here is model:
App.Bookmark = DS.Model.extend({
title: DS.attr("string"),
url : DS.attr("string")
});
Here is controller:
App.BookmarksNewController = Ember.ObjectController.extend({
save: function(){
this.get("model.transaction").commit();
this.get("target").transitionTo("bookmarks");
}
});
In REST implementation in CI that I use standard way to access the post request is $this->input("key"). But when the above request is generated, only raw JSON data is sent. Therefore I don't seem to have a way to reference it in any way.
Take this example:
function post(){
$this->response(var_dump(file_get_contents("php://input")),200);
}
Gives me this output:
string(48) "{"bookmark":{"title":"sdffdfsd","url":"sdfsdf"}}"
what I would like to see is:
string(48) payload="{"bookmark":{"title":"sdffdfsd","url":"sdfsdf"}}"
Then is server I would be able to access this JSON with something like $this->post("payload").
So 1 of 2. Anyway to wrap the JSON payload with key? Or anyway to access raw JSON data in CI with no key available??
Ok figured it out myself (or rather read properly the examples).
When using Adam Whitney's fork of Phil Sturgeons REST controller for CodeIgniter the JSON payload will be available in $this->_post_args. And in the underlying implementation he uses my already mentioned file_get_contents("php://input").
EDIT: Same convention applies for other type of requests as well, for example DELETE request data will be available in $this->_delete_args. Or $this->_args is the "magic" place where all types of args can be found.