offset and limit in the /api/views call - socrata

I am using the the /api/views/.../rows.json call to access the data and the metadata for a dataset, e.g. -
https://data.colorado.gov/api/views/wumm-7awb/rows.json
Problem is I don't want to access all of the data but using limit and offset parameters does not seem to have any effect.
I know about the SODA API endpoint, e.g. https://data.colorado.gov/resource/wumm-7awb.json, that has limit and offset but it doesn't contain the metadata that the /api/views returns
Alternative question - can the /resource API include the metadata?
Thanks

How about using the /resource/wumm-yawb.json endpoint to fetch the data with $limit and $offset and just use /api/views/wumm-yawb.json to fetch the metadata?
What metadata are you looking for? Our team is designing new metadata APIs and it'd be great to know what you're working with.

Related

when using limit and offset in mysql for pagination, how can I tell this is last page or not?

is there any built-in pre-defined mysql method to check if query result with limit offset is last page or not? I found some recommendation to utilize sql_calc_found_rows and found_rows(), but it requires two different query, although I need more simple and straightforward way.
Ultimately, I am using FastAPI and SqlAlchemy right now and I want something equivalent like spring data jpa, Pageable method "isFirst()" and "isLast()". Is there any elegant way to implement those two method using FastAPI and SqlAlchemy?
I know Flast-SqlAlchemy supports hasNext() boolean-returning method, but I guess vanilla SqlAlchemy does not.
A trick I have used before is to get 1 more result than you need and just use it to determine if there is more. You will not know the last page's offset but you will know if the current offset is the last page.
For example if your page_count is something like 10 results then send a limit of 11. Then if you get 10 or less results you know this is the last page but if you get 11 you know there is another page and you show 10 and throw away the 11th result.
Python PSUEDO code
def get_page_of_results(current_offset, PAGE_COUNT=10):
results = session.query(Result).offset(current_offset).limit(PAGE_COUNT + 1).all()
return dict(
is_first=current_offset == 0,
is_last=len(results) < PAGE_COUNT,
next_offset=current_offset + PAGE_COUNT,
# Trim off last result
results=results[:PAGE_COUNT])
The performance between 10 and 11 shouldn't be a big deal unless you are loading huge object trees or something.
Also this method is db agnostic.

interpreting a json string

I have an object in my database following a file upload that look like this
a:1:{s:4:"file";a:3:{s:7:"success";b:1;s:8:"file_url";a:2:{i:0;s:75:"http://landlordsplaces.com/wp-content/uploads/2021/01/23192643-threepersons.jpg";i:1;s:103:"http://landlordsplaces.com/wp-content/uploads/2021/01/364223-two-female-stick-figures.jpg";}s:9:"file_path";a:2:{i:0;s:93:"/var/www/vhosts/landlordsplaces.com/httpdocs/wp-content/uploads/2021/01/23192643-threepersons.jpg";i:1;s:121:"/var/www/vhosts/landlordsangel.com/httpdocs/wp-content/uploads/2021/01/364223-two-female-stick-figures.jpg";}}}
I am trying with no success to parse extract the two jpg urls programmatically from the object so i can show the images ont he site. Tried assigning parse(object) but that isnt helping. I just need to get the urls out.
Thank you in anticipation of any general direction
What you're looking at is not a JSON string. It is a serialized PHP object. If this database entry was created by Forminator, you should use the Forminator API to retrieve the needed form entry. The aforementioned link points to the get_entry method, which I suspect is what you're looking for (I have never used Forminator), but in any case, you should look for a method that will return that database entry as a PHP object containing your needed URLs.
In case it is ever of any help to anyone the answer to the question was based on John input. The API has the classes to handle that without needing to understand the data structure.
Forminator_API::initialize();
$form_id = 1449; // ID of a form
$entry_id = 3; // ID of an entry
$entry = Forminator_API::get_entry( $form_id, $entry_id );
$file_url = $entry->meta_data['upload-1']['value']['file']['file_url'];
$file_path = $entry->meta_data['upload-1']['value']['file']['file_path'];
var_dump($entry); //contains paths and urls
Hope someone benefits.

GoogleDrive API - how to get folder hierarchy from file in python

I using the following code to get all the files in my drive
files_list = service_v3.files().list(corpora='drive',
supportsAllDrives=True,
includeItemsFromAllDrives=True,
driveId=drive['id'],
spaces='drive',
fields='*').execute()
Now in each file I have a parent:
files_list[0]['parents']
How can I get data about this parent?
I've tried to use
service_v2.parents().list(fileId='xxx')
but it does not return much data.
You need to implement three steps:
List all files of interest - as you are already doing with files_list = service_v3.files().list
Loop through the list results or pick a certain file (as you are doing with files_list[0]) and retrieve its parents (as you are doing), e.g. parent = files_list[0].get('parents')
Use the method service_v3.files().get(fileId=parents[0], fields="*").execute() to retrieve the information about the parent by its Id
I recommend you to use the Try It API of the list and get methods in order to get a better understanding of the results those methods give you.
Also, please note that service_v2.parents().list(fileId='xxx') is using the old version of the Drive API (v2), and in any case - if you want to retrieve a file with a specified ID, the correct method to do it is getopposed to list.

CakePHP - How to paging with json data?

I'm training with CakePHP. Currently I have a problem.
I don't know how to paging with json data.
My application will call to API and receive JSON data.
The format look like
{"success":1,"films":[{"film_id":"384","title":"GROSSE WONDERFUL","description":"A Epic Drama of a Cat And a Explorer who must Redeem a Moose in Australia","release_year":"2006","language_id":"1","original_language_id":null,"rental_duration":"5","rental_rate":"4.99","length":"49","replacement_cost":"19.99","rating":"R","special_features":"Behind the Scenes","last_update":"2006-02-15 05:03:42"},{"film_id":"984","title":"WONDERFUL DROP","description":"A Boring Panorama of a Woman And a Madman who must Overcome a Butler in A U-Boat","release_year":"2006","language_id":"1","original_language_id":null,"rental_duration":"3","rental_rate":"2.99","length":"126","replacement_cost":"20.99","rating":"NC-17","special_features":"Commentaries","last_update":"2006-02-15 05:03:42"}]}
This is php code
$data = array('filmId' => $search_data['filmId'], 'filmTitle' => $search_data['filmTitle'], 'releaseYear' => $search_data['releaseYear'], 'rating' => $search_data['rating']);
$HttpSocket = new HttpSocket();
$records = $HttpSocket->post($apiFilmsByConditions, $data);
$records = json_decode($records, true);
I try to use paginate of CakePHP but it seems that this will get data from database, not from API.
This is API link http://oxuhandmade.com/api/get_all_films.php
Can you help me on this case?
Doesn't the API query the database? An API is an "Application programming interface", meaning that it allows you to operate on the database from the "outside", based on a simple interface, triggered by some requests. So there is no point in wanting to limit the results via API, but not via database.
To limit the results an API returns, you need to pass a parameter together with your request, process it in the backend, query the database with the desired limit, and return the results to whoever made the request. Or simply hardcode the desired limit on the API, if it doesn't need to be dynamic.
The Paginator from CakePHP makes this work a whole lot easier, you only have to feed it some conditions and parameters for paginating the results, and it does the magic for you.

RESTful API for related objects

I am fairly new to REST and I have been struggling to map out RESTful requests for objects that are related by foreign keys in a mySQL database.
I have following objects and their relationships are in linear order:
Quiz_course [1]
Quiz_meta_block [2]
Quiz_block [3]
Quiz_question [4]
So far I have come up with the following GET requests:
// Retrieve all quiz_course(s)
api/quiz_course/
// Retrieve quiz_course by id
api/quiz_course/{id}
// Retrieve all quiz_meta_blocks related to a quiz_course id
api/quiz_course/{id}/quiz_meta_block
// Retrieve a quiz_meta_block that is related to a quiz_course_id
api/quiz_course/{id}/quiz_meta_block/{id}
But then I hit a wall when trying to get quiz_questions :
// Retrieve all quiz_questions that is related to a quiz_course_id
api/quiz_course/{id}/quiz_meta_block/quiz_block/quiz_question/
Is my representation accurate ?
I don't know what a block or meta block is in the context of a course, but I would go with something like the below. No need to prefix everything with quiz_*
../courses
../courses/n
../courses/n/meta-blocks
../courses/n/meta-blocks/n
../courses/n/meta-blocks/n/blocks
../courses/n/meta-blocks/n/blocks/n
../courses/n/meta-blocks/n/blocks/n/questions
../courses/n/meta-blocks/n/blocks/n/questions/n
You could also give direct access to, say, all questions in a course like this:
../courses/n/questions