XERO api - Filter prepayments by Contact ID - xero-api

Hi I need to fetch the prepayments done to a particular supplier (with contact id of aa941766-b505-4c0d-ae61-16ee78ec995e) within a given date range
GET https://api.xero.com/api.xro/2.0/Prepayments
query parameters
where = Date >= DateTime(2019, 01, 02) && Date < DateTime(2019, 03, 12) && ContactID = "aa941766-b505-4c0d-ae61-16ee78ec995e"
I am testing in rest client. The resulting GET request
https://api.xero.com/api.xro/2.0/Prepayments?where=Date%20%3E%3D%20DateTime(2019,%2001,%2002)%20%26%26%20Date%20%3C%20DateTime(2019,%2003,%2012)%20%26%26%20ContactID%20%3D%20%22aa941766-b505-4c0d-ae61-16ee78ec995e%22
But getting this 400 error response
{
"ErrorNumber": 16,
"Type": "QueryParseException",
"Message": "No property or field 'ContactID' exists in type 'BankTransaction'"
}

You'll need to follow the structure of the object you're expecting in the response: the ContactID property is in the Contact element of the Prepayment, so maybe try Contact.ContactID instead of just ContactID.
You also need to parse the ContactID guid for use in the where clause, like this:
Contact.ContactID==Guid("aa941766-b505-4c0d-ae61-16ee78ec995e")

Related

Prisma queryRaw returning date as string

Issue: When I use prisma.$queryRaw, it returns my date as a string, even though I specify the query's return type. If I use prisma.find then it returns it correctly. But, I have to use queryRaw because of the complexity of the query.
schema.prisma has the date defined like such:
effectiveDate DateTime? #map("effective_date") #db.Date
So, the model object has the field defined like effectiveDate: Date | null
The query looks something like this:
const catalogCourses: CatalogCourse[] = await prisma.$queryRaw<CatalogCourse[]>`
SELECT
id,
campus,
effective_date as "effectiveDate",
...rest of the query ommitted here because it's not important
If I then do something like
console.log(`typeof date: ${typeof catalogCourses[0].effectiveDate}, value ${catalogCourses[0].effectiveDate}`)
The result shows typeof date: string, value 2000-12-31. Why isn't it a date? I need to be able to work with it as a Date, but if I do effectiveDate.getTime() for example, it errors during runtime, saying 'getTime is not a function', which it is doc. If I try and do new Date(effectiveDate), that doesn't work either because typescript sees the field as a Date object already. EDIT: I was incorrect about why the previous statement wasn't working; doing new Date(effectiveDate) does work.
I do see in the prisma docs that it says:
Type caveats when using raw SQL When you type the results of
$queryRaw, the raw data does not always match the suggested TypeScript
type.
Is there a way for queryRaw to return my date as a Date object?

Accessing values in JSON array

I am following the instruction in the documentation for how to access JSON values in CloudWatch Insights where the recomendation is as follows
JSON arrays are flattened into a list of field names and values. For example, to specify the value of instanceId for the first item in requestParameters.instancesSet, use requestParameters.instancesSet.items.0.instanceId.
ref
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_AnalyzeLogData-discoverable-fields.html
I am trying the following and getting nothing in return. The intellisense autofills up to processList.0 but no further
fields processList.0.vss
| sort #timestamp desc
| limit 1
The JSON I am woking with is
"processList": [
{
"vss": xxxxx,
"name": "aurora",
"tgid": xxxx,
"vmlimit": "unlimited",
"parentID": 1,
"memoryUsedPc": 16.01,
"cpuUsedPc": 0.01,
"id": xxxxx,
"rss": xxxxx
},
{
"vss": xxxx,
"name": "aurora",
"tgid": xxxxxx,
"vmlimit": "unlimited",
"parentID": 1,
"memoryUsedPc": 16.01,
"cpuUsedPc": 0.06,
"id": xxxxx,
"rss": xxxxx
}]
Have you tried the following?
fields ##timestamp, #processList.0.vss
| sort ##timestamp desc
| limit 5
It may be a syntax error. If not, please post a couple of records worth of the overall structure, with #timestamp included.
The reference link that you have posted also states the following.
CloudWatch Logs Insights can extract a maximum of 100 log event fields
from a JSON log. For extra fields that are not extracted, you can use
the parse command to parse these fields from the raw unparsed log
event in the message field.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_AnalyzeLogData-discoverable-fields.html
For very large JSON messages, Insights intellisense may not be parsing all the fields into named fields. So, the solution is to use parse on the complete JSON string in the field where you expect your data field to be present. In your example and mine it is processList.
I was able to extract the value of specific cpuUsedPc under processList by using a query like the following.
fields #timestamp, cpuUtilization.total, processList
| parse processList /"name":"RDS processes","tgid":.*?,"parentID":.*?,"memoryUsedPc":.*?,"cpuUsedPc":(?<RDSProcessesCPUUsedPc>.*?),/
| sort #timestamp asc
| display #timestamp, cpuUtilization.total, RDSProcessesCPUUsedPc

Qliksense REST offset pagination using loop

I need to paginate through all of the records from Hubspot API and I am getting stuck at offset pagination loop.
According to the Hubspot's API documentation, there is no "total records" path available in the response but instead "has-more" filed tells us if there are any more records we can pull from this portal.
two parameters that can be used for pagination are
vidOffset & has-more
here's what qliksense script looks like for custom pagination via rest connector.
LIB CONNECT TO 'HubSpot ';
// Action required: Implement the logic to retrieve the total records from the REST source and assign to the 'total' local variable.
Let total = 0;
Let totalfetched = 0;
Let startAt = 0;
Let pageSize = 100;
for startAt = 0 to total step pageSize
RestConnectorMasterTable:
SQL SELECT
"has-more",
"vid-offset",
"__KEY_root",
(SELECT
"addedAt",
"vid" AS "vid_u0",
"canonical-vid",
"portal-id",
"is-contact",
"profile-token",
"profile-url",
"__KEY_contacts",
"__FK_contacts",
(SELECT
"#Value",
"__FK_merged-vids"
FROM "merged-vids" FK "__FK_merged-vids" ArrayValueAlias "#Value"),
(SELECT
"__KEY_properties",
"__FK_properties",
(SELECT
"value",
"__FK_firstname"
FROM "firstname" FK "__FK_firstname"),
(SELECT
"value" AS "value_u0",
"__FK_lastmodifieddate"
FROM "lastmodifieddate" FK "__FK_lastmodifieddate"),
(SELECT
"value" AS "value_u1",
"__FK_company"
FROM "company" FK "__FK_company"),
(SELECT
"value" AS "value_u2",
"__FK_lastname"
FROM "lastname" FK "__FK_lastname")
FROM "properties" PK "__KEY_properties" FK "__FK_properties"),
(SELECT
"#Value" AS "#Value_u0",
"__FK_form-submissions"
FROM "form-submissions" FK "__FK_form-submissions" ArrayValueAlias "#Value_u0"),
(SELECT
"vid",
"saved-at-timestamp",
"deleted-changed-timestamp",
"__KEY_identity-profiles",
"__FK_identity-profiles",
(SELECT
"type",
"value" AS "value_u3",
"timestamp",
"is-primary",
"__FK_identities"
FROM "identities" FK "__FK_identities")
FROM "identity-profiles" PK "__KEY_identity-profiles" FK "__FK_identity-profiles"),
(SELECT
"#Value" AS "#Value_u1",
"__FK_merge-audits"
FROM "merge-audits" FK "__FK_merge-audits" ArrayValueAlias "#Value_u1")
FROM "contacts" PK "__KEY_contacts" FK "__FK_contacts")
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(Url "https://api.hubapi.com/contacts/v1/lists/all/contacts/all");
// Action required: change URL included in 'WITH CONNECTION' as needed to support pagination for the REST source.
// Please see the documentation for "Loading paged data."
NEXT startAt;
Need to understand how to set this up as per my API paramteres i.e. offset & hasmore property. How do i loop through all of the vidoffset values so that i can get all of the records until has-more becomes false?
Here's my json response
Please try recursive call to do you need to put your call in subroutine than check for has_more and if it is equal to True call subroutine again. Also Url parameter have to be updated every time with new vid-offset value. Here is example (tested it is working):
SUB getOnePage(vOffset)
LIB CONNECT TO [hubspot_api];
RestConnectorMasterTable:
SQL SELECT
(...)
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (Url "https://api.hubapi.com/contacts/v1/lists/all/contacts/all/?hapikey=YOURKEY=$(vOffset)");
LET vHasMore = Peek('has-more',-1);
LET vVidOffset = Peek('vid-offset',-1);
DROP Table root;
IF vHasMore = 'True' then
CALL getOnePage($(vVidOffset));
EndIf
EndSub
Because of repeated keys in every CALL we need to change settings in REST connector as follow:

Fusion table SQL query fails with numbers

I'm making a tiny webapp to see what are the pub's specials around you and I have a very silly problem with my SQL query to fusion table.
Here is my table and her is my query:
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
AND from <= 2000
AND to >= 2000
My problem is with the from and to, if I remove them my query is fine and if I simplify them (remove from and put just to > 0) my query is still wrong.
As you can see in my fusion table, from and to are both numbers so I really don't get what's wrong.
EDIT:
So I'm using https://developers.google.com/apis-explorer/#p/fusiontables/v2/fusiontables.query.sql to test my queries:
Good query (200 OK):
SELECT *
FROM 1BHnaan3YfSDq9_LzjthDXjj5dzJZANjLSb8JHPl5
WHERE
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
Bad query:
SELECT *
FROM 1BHnaan3YfSDq9_LzjthDXjj5dzJZANjLSb8JHPl5
WHERE
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
AND from <= 1619
AND to >= 1619
I get this error but I don't see what's wrong because <= is in the docs:
{
"error": {
"errors": [
{
"domain": "fusiontables",
"reason": "badQueryCouldNotParse",
"message": "Invalid query: Parse error near 'from' (line 1, position 218).",
"locationType": "parameter",
"location": "q"
}
],
"code": 400,
"message": "Invalid query: Parse error near 'from' (line 1, position 218)."
}
}
from & to are reserved words in fusion table, here is the list of reserved words:
AND
ASC
AS
BY
CASE
CIRCLE
CONTAINS
CONTAIN
CREATE
DELETE
DESCRIBE
DESC
DOES
DROP
ENDS
EQUAL
FROM
GROUP
IGNORING
IN
INSERT
INTO
LATLNG
LIKE
LIMIT
MATCHES
NEAR
NOT
OFFSET
ORDER
POLYGON
RECTANGLE
ROWID
SELECT
SET
SHOW
SKIP
ST_DISTANCE
ST_INTERSECTS
STARTS
TABLES
TABLE
TO
UPDATE
VALUES
VIEW
WHERE
WITH
ID
NUMBER
DOCID
STRING
I figured it out because they were blue in the syntax highlighting in my question.
If you try that query from the Fusion Tables UI, you also see no results, because no values match those criteria. The days are "monday" and "tuesday", and the times are 1130-1400 and 1800-2359.

How do I pass parameter as Date in vb.net web?

I have a mail webform where I have to show the user only (-1) one day behind messages, so how do pass (yesterday)date as parameter and retrieve the only records of one day back ?
This query is for 'ALL' messages, but I need to filter (yesterday) one day back messages and add a hyperlink or add in a dropdown ?
select MSG_SRNO,MSG_SUBJECT,MSG_ID,MSG_CHKD,
DOF_SENT,DOF_SEEN from MESSAGES_MAILBOX where USER=1234
In sql, try
SELECT DATEADD(day,-1, GETDATE());
This should work:
DateTime yesterday = DateTime.Now.AddDays(-1);
string query = string.Format("select MSG_SRNO,MSG_SUBJECT,MSG_ID,MSG_CHKD,DOF_SENT,DOF_SEEN from MESSAGES_MAILBOX where DATEPART(year,DOF_SENT) = {0} AND DATEPART(month,DOF_SENT) = {1} AND DATEPART(day,DOF_SENT) = {2}",yesterday.Year,yesterday.Month, yesterday.Day);