Request.post arguments in python - json

Is there a way to determine the max value of an argument in a requests.post command to a website if we don't know the amount of data in the website's dataset? I'm trying to execute the following code to get specific information on all daycares from this website, but don't know the value of the last argument (length). Currently, I'm assuming this value is 20, but it is subject to change from time to time. How do I keep it open ended so I don't have to guess the max value for lenth? Code as follows:
data_requested = requests.post("https://data.nj.gov/views/INLINE/rows.json?"
"accessType=WEBSITE&method=getByIds&asHashes=true&start=0&length=20",
json=data)
njcc_data = data_requested.json()

Notice that this has nothing to do with requests.post - the range of values length can take is determined by the creator of that API and is an unknown quantity both to you and to requests.
You can try to reason about what possible values it could take, is it the length of a person? If yes, it's probably not going to be more than 250cm.
You can also use trial and error and see how high you can make it before the API endpoint gives back an error, but I guess this is what you were trying to avoid.
If length is the number of items returned (the length of the returned json array) then you could just try setting it to a high number like 1000 and see if you can get away with it.

Related

How to calculate pagination in magritte YAML configs?

I'm looking to pull data from a REST API that uses a record offset system. I need to perform basic arithmetic on the returned (current_offset + item_count) data to calculate the next offset.
Unfortunately, this API uses a variable page size, so simple offsets won't work. Nor does it return the next offset to use in the response, just the component values.
However, it appears that there's no way to do even basic arithmetic that I can see. Am I just missing it?

How to properly set a conditional statement in sequence?

I'm trying to set a conditional statement in web methods. I think I'm on the right path and missing couple small steps trying to get it done.
So my branch is going is going through a path. /barcode
Then the sequence's job is to keep the length 18 or below characters. My label in the sequence looks like this: (%barcode%)<=18.
This flow is getting skipped over.
if you are trying to find the length of the value in barcode. Use this service pub.string:length in a map step to find out the length and then use that length for the comparison.

Use 'forceget' error when calling GET :urn/​metadata/​:guid/​properties

I am trying to retrieve the properties using this method: GET :urn/​metadata/​:guid/​properties
This is something that we have running and works daily in our workflows, but I think this is an especailly large model.
For this particular model we are getting the following repsonse:
413 Request Entity Too Large
{Diagnostic": "Please use the 'forceget' parameter to force querying the data."}
Can anyone advise me as to how I do apply the forceget parameter to this call as I can't see any mention of it in the api docs.
forceget (string): To force get the large resource even if it exceeded the expected maximum length. Possible values: true, false. The implicit value is false.
The maximum data size 'without' forceget=true, is 2097152 bytes gzip compressed.
If you add 'forceget' then there is no size limit, however, if the generation of the gzip file takes longer than 2 hours, it will time out and try again later and eventually give up and report an error.
More details in this blog post: https://forge.autodesk.com/blog/faster-get-hierarchy-api-and-how-solve-error-413
#augusto-goncalves. Do you know what is the max number of parameters that are possible to get through a request with 'forceget' param?
... and what is the maximum number of properties we might have in the model so that we can retrieve all properties from that endpoint WITHOUT using 'forceget' parameter?

MediaWiki not returning continue parameter

I'm using this API request:
https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=10000&gscoord=51.540951897949|-0.051086739997922&format=json&gslimit=50&continue=
which delivers 50 results. I want to use the 'continue' parameter to get the next page of results. According to the documentation I should get a continue field back in the results. I don't get any such result so can't get the next page.
Does anyone have any suggestions?
Dave, as #svick says, it seems list=geosearch (which is part of extension:GeoData) does not support continuation; indeed, it actually returns a "batchcomplete" element to indicate no more results (see in human-readable form).
I think you should either just get the maximum number of results (500 for users, 5000 for bots on Wikipedia), or if that's not satisfactory for your use case (which is?), pipe in at task T78703.
(Or, if you believe it to be a separate issue, report a new bug.

Using $skip with the SharePoint 2013 REST API

Forgive me, I'm very new to using REST.
Currently I'm using SP2013 Odata (_api/web/lists/getbytitle('<list_name>')/items?) to get the contents of a list. The list has 199 items in it so I need to call it twice and each time ask for a different set of items. I figured I could do this by calling:
_api/web/lists/getbytitle('<list_name>')/items?$skip=100&$top=100
each time changing however many I need to skip. The problem is this only ever returns the first 100 items. Is there something I'm doing wrong or is $skip broken in the OData service?
Is there a better way to iterate through REST calls, assuming this way doesn't work or isn't practical?
I'm using the JSon protocol with the Accept Header equaling application/json;odata=verbose
I suppose the $top=100 isn't really necessary
Edit: I've looked it up more and, I'm not entirely sure of the terms here, but using $skip works fine if you're using the method introduced with SharePoint 2010, i.e., _vti_bin/ListData.svc/<list_name>?$skip=100
Actually, funny enough, the old way doesn't set a 100 item limit on returns. So skip isn't even necessary. But, if you'd like to only return a certain segment of data, you'd have to do something like:
_vti_bin/ListData.svc/<list_name>?$skip=x&$top=(x+y)
where each time through the loop you would have something like x+=y
You can either use the old method which I described above, or check out my answer below for an explanation of how to do this using SP2013 OData
Alright, I've figured it out. $skip isn't a command which is meant to be used at the items? level. It works only at the lists? level. But, there's a way to do this, actually much easier than what I wanted to do.
If you just want all the data
In the returned data, assuming the list you are calling holds more than 100 items, there will be a __next at d/__next (assuming you are using json). This __next (it is a double underscorce, keep that in mind. I had a few problems at first because I was trying to get d/_next which never returned anything) is the right URL to get the next set of items. __next will only ever be a value if there is another set of items available to get.
I ended up creating a RequestURL variable which was initially set to to original request, but was changed to d/__next at the end of the loop. Then the loop went and checked if the RequestURL was not empty before going inside the loop.
Forgive my lack of code, I'm using SharePoint Designer 2013 to make this, and the syntax isn't horribly descriptive.
If you'd only like a small set of data
There's probably a few situations where you would only want x amount of rows from your list each time you go through the loop and that's real easy to do as well.
if you just add a $top=x parameter to your request, the __next URL that comes back with the response will give you the next x rows from your list. Eventually when there are no rows left to return __next won't be returned with the response.
Don't forget that in order to use __next you need to have a
$skiptoken=Paged=TRUE
in the url as well.