I am currently working something that need to get the data from RETS, where I can extract information from RETS but cannot get the image. I tried to use the following code:
$photos = $rets->GetObject("Property", "Photo", $record['L_ListingID'], "*", 1);
if ($photos !== null) {
foreach ($photos as $photo){
var_dump ($photo);
}
}
and receive the result below:
object(PHRETS\Models\Object)#71 (10) {
["content_type":protected]=>
string(8) "text/xml"
["content_id":protected]=>
string(9) "261860123"
["object_id":protected]=>
string(1) "1"
["mime_version":protected]=>
NULL
["location":protected]=>
NULL
["content_description":protected]=>
NULL
["content_sub_description":protected]=>
NULL
["content":protected]=>
string(71) "
"
["preferred":protected]=>
NULL
["error":protected]=>
object(PHRETS\Models\RETSError)#73 (2) {
["code":protected]=>
int(0)
["message":protected]=>
string(0) ""
}
}
as the code suggested, I can only get "text/xml" returned as the content_type of the object, where I should be expecting a jpg file. How can I get the image and not get the text as a result?
If you can get the MLS number, this will help you out.
$photo = $rets->GetObject('Property', 'Photo', $mls, 1, 1);
$mls is the mls number, the first '1' gets you the first image, and the second 1 will get you the URL. If you want the actual image to download, the second '1' will need to be '0'. If you make the first '1' a '*' then you'll get all of the images for that MLS.
To test take a known mls number from you mls and enter it as shown below.
Get the url of all images can be as many as 100+
$photos = $rets->GetObject("Property", "Photo", 123456789, "*", 1);
Get url of 1st image
$photos = $rets->GetObject("Property", "Photo", 123456789, "1", 1);
Get url of 5th image
$photos = $rets->GetObject("Property", "Photo", 123456789, "5", 1);
Get all physical images can be as many as 100+
$photos = $rets->GetObject("Property", "Photo", 123456789, "*", 0);
Get 1st physical image
$photos = $rets->GetObject("Property", "Photo", 123456789, "1", 1);
Get 5th physical image
$photos = $rets->GetObject("Property", "Photo", 123456789, "5", 1);
Then you must store the image URLs in a data base and if you are getting actual images you must store them in a directory.
If you had provided more info on $record['L_ListingID'], how you got this I would be able to tell you if it contained the MLS number as it must to be able to do what you are trying to do...
Related
I am getting less count than actual web ui that I download as csv.
There are around 35k entries but I am getting only 600 something.
Here is my code.
dimensions = ["sessionSource","customEvent:order_id","date","platform"]
metrics = ['sessions']
request = {
"requests": [
{
"dateRanges": [
{
"startDate": "2022-10-15",
"endDate": "2022-10-17"
}
],
"dimensions": [{'name': name} for name in dimensions],
"metrics": [{'name': name} for name in metrics],
"limit": 10,
"return_property_quota": True,
"keep_empty_rows": True,
"data_loss_from_other_row": False
}
]
}
analytics = build('analyticsdata', 'v1beta', credentials=credentials)
response = analytics.properties().batchRunReports(property=property_id,
body=request).execute()
report_data = defaultdict(list)
I see limit is set to 10 in your query. If this is set, the response will only contain 10 rows.
This is a weird one.
I'm using datatables v1.10.19 with jQuery 3.3.1 and Bootstrap 3.3.7
My datatables grid is configured to display 1000 records (but you can change it to 2500, 5000 and "all").
I've only got about 60 records in my database.
It is using Server-Side processing to retrieve data.
When the grid loads, the pager displays 5 buttons plus an ellipses (as if there is even more).
And even weirder, if I change the drop-down to display "all" records, it acts as I would expect i.e. the pager has 1 page button.
The payloads are pretty much identical:
{
"data": {
"draw": 8,
"recordsTotal": 86,
"recordsFiltered": 66,
"data": [rows of data here]
},
"outcome": {
"opResult": "Success",
"message": ""
}
}
When you click on page 2, it does successfully retrieve a payload with 0 rows.
But there shouldn't be a page 2 available on the pager.
The config object for the datatable looks like this:
eventsSvr.buildConfig = function (url) {
return {
"processing": true,
"serverSide": true,
//"paging": true,
"ajax": {
url: url,
type: ajax.requestPOST,
dataSrc: 'data.data' // the path in the JSON structure to the array which will be the rows.
},
"order": [[1, "asc"]],
"lengthMenu": [[1000, 2500, 5000, -1], [1000, 2500, 5000, "All"]],
"initComplete": function (settings, json) {
eventsSvr.searchTextSpan.text('Search').removeClass('search-is-on');
},
"columns": eventsSvr.grid.columns,
"columnDefs": eventsSvr.grid.columnDefs,
dom: 'ltp'
};
I do have a bunch of custom searches on the page, so I've had to write a lot of code like this:
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var picker3 = $(eventsSvr.datePickerInputs[0]).data(icapp.kendoKey);
var picker4 = $(eventsSvr.datePickerInputs[1]).data(icapp.kendoKey);
var rowStartDate = moment(data[3], icapp.date.momentParseFormat).toDate();
var rowEndDate = moment(data[4], icapp.date.momentParseFormat).toDate();
... etc.
}
);
But the odd thing is the different behavior as between "All" records vs 1000 records.
As described above, select "All" records works (resulting in just 1 page button), but none of the other paging sizes work (i.e. 1000, 2500, 5000). The data for the 1 page does return, but I get 5 page buttons and an ellipses.
Any ideas why this would be happening?
When using server-side processing mode DataTables expects draw, recordsTotal and recordsFiltered to be root-level elements. Consider changing your repsonse to the following and you can remove dataSrc option.
{
"draw": 8,
"recordsTotal": 86,
"recordsFiltered": 66,
"data": [rows of data here],
"outcome": {
"opResult": "Success",
"message": ""
}
}
Alternatively you can manipulate the response before passing it to DataTables using function supplied as value for dataSrc option, but I would recommend keep things according to expected format for more readable code.
I am able to authenticate against the SAGE ONE API and also able to retrieve data from the API however I am now trying to post a simple invoice however keep getting a 422 error. Is there something obvious I am missing?
I have double checked the JSON structure and the values i am providing and are all valid. Not sure what i am doing wrong here!
my JSON package looks like this
{"contact_id":"66b76fa19edc11e797950a57719b2edb",
"date":"2019-04-13",
"invoice_lines":[{"description":"Test Description",
"ledger_account_id":"0367afd89ece11e797950a57719b2edb","quantity":1,"unit_price":100}]}
code
Dim http As HttpWebRequest = WebRequest.Create(New Uri("https://api.columbus.sage.com/uki/sageone/accounts/v3/sales_invoices"))
http.Method = "POST"
http.ContentType = "application/json"
http.Accept = "application/json"
http.Headers.Add("X-Site", "mysite")
http.Headers.Add("ocp-apim-subscription-key", "mykey")
http.Headers.Add("Authorization", "Bearer " mytoken)
Dim data = Encoding.UTF8.GetBytes(json)
http.ContentLength = data.Length
Dim stream = http.GetRequestStream()
stream.Write(data, 0, data.Length)
stream.Close()
Dim response = http.GetResponse().GetResponseStream()
This POST body worked for me (with different ids):
{
"sales_invoice": {
"contact_id": "66b76fa19edc11e797950a57719b2edb",
"date": "2019-04-13",
"main_address": { "address_line_1": "42 Test Street" },
"invoice_lines": [
{
"description": "Test Description",
"ledger_account_id": "0367afd89ece11e797950a57719b2edb",
"quantity": 1,
"unit_price": 100,
"tax_rate_id": "GB_NO_TAX"
}
]
}
}
You need to wrap your JSON structure with a key, which is the name of your resource ("sales_invoice" in this case).
You also need to specify a main address, as well as a tax rate id for each line item.
To be sure to have a valid ledger account for your sales invoice, get a list of possible accounts with:
GET /ledger_accounts?visible_in=sales
As a beginner I have few questions. I am using the Get request, which would populate json below.
https://reqres.in/api/users
{
"total": 12,
"total_pages": 4,
"data": [{
"id": 1,
"first_name": "George",
"last_name": "Bluth",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg"
}]
}
for the 2 tests below while the 1st one passes the 2nd test fails with the message:
AssertionError: expected false to be truthy
//Verify Page number total is 12
var jsonData = JSON.parse(responseBody);
tests["Checking total page number-Manual"] = jsonData.total === 12;
//verify is exists and is 1
var jsonData = JSON.parse(responseBody);
tests["Checking ID exists and is 1"] = jsonData.id === 1;
Question 1:
A github post that I found says there may be an error and suggests to use
the new pm.* equivalent instead. However I do not see any difference between the 1st and the 2nd. So why does the 2nd test fail?
Question 2:
Is it possible to write test to verify that for ID:1 the firstname is George?
Thanks in advance for your time.
The reason that your 2nd test fails is because data is an array and in this case you must access the first element. You would want to do something like this (new syntax):
pm.test("Verify id is equal to 1", function() {
var jsonData = pm.response.json();
pm.expect(jsonData.data[0].id).to.equal(1);
});
Similarly for testing first name is George:
pm.test("Verify id is equal to 1", function() {
var jsonData = pm.response.json();
pm.expect(jsonData.data[0].first_name).to.equal("George");
});
If you always expect it to only be a single element in the array then you're safe to use index 0 i.e. data[0]. However if you expect there to be more elements in the data array then you would have to iterate through them to look for the correct element.
Here's a good reference for the API:
https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/
I'm trying to get a search list for a specific keyword from the YouTube API.
I've tried: https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=elanco&key={MY API KEY}
And it only gives me the first 50 Results. So I changed "maxResults" to equal 2000.
But then this error occurs:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid value '2000'. Values must be within the range: [0, 50]",
"locationType": "parameter",
"location": "maxResults"
}
],
"code": 400,
"message": "Invalid value '2000'. Values must be within the range: [0, 50]"
}
}
Does anyone know how I can get more than 50 results? My keyword generates around 1500 results, I want to be able to see all of them.
Thanks!
As per the docs, maxResults param having restriction [Acceptable values are 0 to 50, inclusive. The default value is 5].
So per one request you can get the 50 records at Max, if you see in the result of your first hit , you will get nextPageToken field (starting from first , except the last page,as this is the last page ) and prevPageToken (starting from second page, as there will be no prev page for the first page) field in response to the request.
Now we can use these values (nextPageToken/prevPageToken) to fetch records for the next or prev 50 records by passing the value to the query parameter
pageToken = < value of nextPageToken for the next set of records>
or < for prev use prevPageToken>.
In short, Add the pageToken param to the subsequent requests till the count equals pageInfo.totalResults !!!
Thanks!!!
Use the nextPageToken to get the next resultset. There is some restrictions, the API can only return max of 50 restultet at a time. But using the nexPageToken element you can get the next 50 resultset
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/FSbRmodfOD2HSQzA29X7Tn2Mupc\"",
"
nextPageToken": "CAIQAA"
"pageInfo": {
"totalResults": 199,
"resultsPerPage": 2
},
"items": [