In implementing a custom webhook handler for Gitlab issues, I'm struggling to find out how to determine the previous value of a field before the hook fired.
For reference, this is the webhooks documention, and an issue-specific payload looks a bit like:
{
"object_attributes": {
"action": "update",
"url": "https://example.com/foo/bar/issues/10",
"iid": 10,
"state": "opened",
"milestone_id": null,
"description": "44",
"branch_name": null,
"position": 0,
"updated_at": "2015-11-07 17:39:47 +0000",
"created_at": "2015-11-07 17:06:07 +0000",
"project_id": 51,
"author_id": 6,
"assignee_id": null,
"title": "123",
"id": 180
},
"user": {
"avatar_url": "https://example.com/uploads/user/avatar/6.jpg",
"username": "shabble",
"name": "real name"
},
"object_kind": "issue"
}
when an issue is modified.
In this example, the assignee_id was changed from myself to null, but there appears to be no way to determine what the previous value (that is, me) was prior to update.
This is the same for almost all editable fields, including things like the entire issue description. So it's possible to tell what it is now, and maybe when it was last changed, but not see any of the previous changes.
Is there anywhere this information (previous state) can be found, perhaps via the gitlab issues API although I've not found anything plausible.
The only option seems to be a separate system to record the values from every hook, and then when a subsequent hook comes in that matches the same issue, diff the last record to determine changes. This would be less than ideal.
Any other ideas?
Related
This question was originally asked in the shopify community, but without any response. So sorry for those of you reading this as duplicate.
We are trying to strengthen our Shopify webhook receiver and reconciliation jobs. The json object below show a list of events from an order we have processed. Examine the created_at timestamps show that 3 events was triggered within the same timestamp.
I assume that 3 webhooks are fired on topic orders/updated and the order updated_at timestamp is 2022-04-26T11:10:57+02:00 after the 3 events.
In the case where the first, of the 3, orders/updated hooks fails on our side, and retried by shopify. How can we make sure that we have the latest event, since comparing the order updated_at timestamp would properly be the same for all 3 events?
We are facing a similar issue with our reconciliation job, since we are comparing the order updated_at timestamp. as an example, if we received the first and second hooks from the example sequence below, the reconciliation job would compare updated_at timestamp and skip the rescue! How can we overcome this, without sync all orders in our reconciliation jobs?
We run the reconciliation jobs once a day and sync all orders by that job is not possible within the rate limit of 2 calls/sec for the REST API.
Thanks in advance
Mads
{
"events": [
{...},
{
"id": 90448362045627,
"subject_id": 1000,
"created_at": "2022-04-26T11:10:53+02:00",
"subject_type": "Order",
"verb": "fulfillment_success",
"arguments": [
],
"body": null,
"message": "CoolRunner fulfilled 1 item ",
"author": "CoolRunner",
"description": "CoolRunner fulfilled 1 item ",
"path": "/admin/orders/1000/fulfillments/3862202974395"
},
{
"id": 90448362275003,
"subject_id": 1000,
"created_at": "2022-04-26T11:10:54+02:00",
"subject_type": "Order",
"verb": "mail_sent",
"arguments": [
],
"body": null,
"message": "CoolRunner sent a shipping confirmation email ",
"author": "CoolRunner",
"description": "CoolRunner sent a shipping confirmation email",
"path": "/admin/orders/1000"
},
{
"id": 90448363258043,
"subject_id": 1000,
"created_at": "2022-04-26T11:10:57+02:00",
"subject_type": "Order",
"verb": "capture_success",
"arguments": [
],
"body": null,
"message": "CoolRunner captured €99.00 EUR using a Mastercard ",
"author": "CoolRunner",
"description": "CoolRunner captured €99.00 EUR using a Mastercard ",
"path": "/admin/orders/1000/transactions/5355897323707"
},
{
"id": 90448363389115,
"subject_id": 1000,
"created_at": "2022-04-26T11:10:57+02:00",
"subject_type": "Order",
"verb": "payments_charge",
"arguments": [
],
"body": null,
"message": "-",
"author": "CoolRunner",
"description": "-",
"path": "/admin/orders/1000"
},
{
"id": 90448363421883,
"subject_id": 1000,
"created_at": "2022-04-26T11:10:57+02:00",
"subject_type": "Order",
"verb": "closed",
"arguments": [],
"body": null,
"message": "This order was archived.",
"author": "Shopify",
"description": "This order was archived.",
"path": "/admin/orders/1000"
}
]
}
Not sure I understand your problem, but you have to understand, if you choose to function via handling webhooks, things like temporal ordering go out the window. You have to code for that. You will never have a guarantee that any one webhook will arrive in any kind of order. So you just process them and move on.
So if an order undergoes three updates, 1, 2, and 3, you might receive webhook notifications in the order 3,2,1 or 1,3,2, or 2,3,1 or 1,2,3 or 3,1,2 etc.
So you have exposed two problems. One, you are trusting Webhooks are a source of temporal truth and, two, you are painting yourself into a corner by not doing your API coding to respect API limits.
My advice to you is to accept webhooks when they arrive, process them, and improve your code so API limits are not holding you back.
I am attempting to make a simple room booking application within my office. Users can select a time frame, see the available rooms, and book the room (create an event in their calendar in that time frame in that room).
In order to see what rooms are available, I am attempting to use the Microsoft Graph REST API, and specifically the POST method - getSchedule.
An example request for getSchedule looks like this
{
"schedules": ["adelev#contoso.onmicrosoft.com", "meganb#contoso.onmicrosoft.com"],
"startTime": {
"dateTime": "2019-03-15T09:00:00",
"timeZone": "Pacific Standard Time"
},
"endTime": {
"dateTime": "2019-03-15T18:00:00",
"timeZone": "Pacific Standard Time"
},
"availabilityViewInterval": "60"
}
I place all of the rooms in the office in the schedules list, and then can see their availabilities in the response based on the availability view.
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.scheduleInformation)",
"value": [
{
"scheduleId": "adelev#contoso.onmicrosoft.com",
"availabilityView": "000220000",
"scheduleItems": [
{
"isPrivate": false,
"status": "busy",
"subject": "Let's go for lunch",
"location": "Harry's Bar",
"start": {
"dateTime": "2019-03-15T12:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-15T14:00:00.0000000",
"timeZone": "Pacific Standard Time"
}
}
],
"workingHours": {
"daysOfWeek": [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday"
],
"startTime": "08:00:00.0000000",
"endTime": "17:00:00.0000000",
"timeZone": {
"name": "Pacific Standard Time"
}
}
},
However, I don't need any of the other information provided in the response. I only want to see the scheduleId and the availabilityView, because the response takes forever to load with many rooms in the schedules request.
I've been looking at the available ways to filter a response through parameters in the POST request at: https://learn.microsoft.com/en-us/graph/query-parameters. However, any of the filters I seem to apply to my address do not seem to have any affect on the response.
I've tried
https://graph.microsoft.com/v1.0/me/calendar/getschedule?$select=availabilityView
for the request and other similar variants without any success. They all return the full JSON response.
It is a OData protocol limitation. Querying Data is only possible on GET requests as documented here.
Besides asking for less rooms to begin with. a shorter period or a bigger interval, I don't think there a way to get less data today.
I'm using HERE Places API.
Firstly I'm doing a search.
For Example this query :
https://places.cit.api.here.com/places/v1/discover/search?q=Test&at=35.6111,-97.5467&r=500&size=1&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid&pretty
According to this documentation (Link) If I add show_refs=pvid to query string, in result I will get external id which I can use to query lookup endpoint.
But in result I get next response :
{
"results": {
"next": "https://places.cit.api.here.com/places/v1/discover/search;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmb2Zmc2V0PTEmc2l6ZT0x?at=35.6111%2C-97.5467&q=Test&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"items": [
{
"position": [
35.60369,
-97.51761
],
"distance": 2756,
"title": "Southwest Test & Balance",
"averageRating": 0,
"category": {
"id": "business-services",
"title": "Business & Services",
"href": "https://places.cit.api.here.com/places/v1/categories/places/business-services?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/02.icon",
"vicinity": "200 NW 132nd St<br/>Oklahoma City, OK 73114",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"id": "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
"authoritative": true
}
]
},
"search": {
"context": {
"location": {
"position": [
35.6111,
-97.5467
],
"address": {
"text": "Oklahoma City, OK 73134<br/>USA",
"postalCode": "73134",
"city": "Oklahoma City",
"county": "Oklahoma",
"stateCode": "OK",
"country": "United States",
"countryCode": "USA"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPU9rbGFob21hK0NpdHk7bGF0PTM1LjYxMTE7bG9uPS05Ny41NDY3O2NpdHk9T2tsYWhvbWErQ2l0eTtwb3N0YWxDb2RlPTczMTM0O2NvdW50cnk9VVNBO3N0YXRlQ29kZT1PSztjb3VudHk9T2tsYWhvbWE7Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg"
}
}
}
In response no object references
Is it a bug or not every place has this external id?
I am responding as member of the team around HERE Places API.
Yes, not every place has a pvid. That is why I would suggest using the Sharing Id instead. I realize that the documentation should be improved to clarify that.
The Sharing Ids can be obtained by adding show_refs=sharing to either your search query or a place details request. It can be found in the field references. Once you have the sharing id you can you the lookup endpoint as you intended.
Take a look at:
https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
and
https://places.cit.api.here.com/places/v1/places/8409q8yy-6af3c3e50bcb4f859686797b2be5773d;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
On those two examples, the only difference is the placeId.
In the docs, there's not a single reference saying that the external identifier is required or existant for every place.
Since it represents an external identifier, I believe we could assume that it's not required.
And it's what we just saw with your place (8403fv6k-d1b2fde0616e0326e321a54b88cd9f53): this one don't have any external identifier.
Based on your comments, what you need is the information about a place.
So, after you run your first query, you should get something like:
{
title: "Southwest Test & Balance",
position: [],
id: "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
href: "https://[...]"
}
With this ID, you could access it:
places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD0zYTFlZjg5ZS02ZTY5LTUxYmEtYWFkYS1kY2UwZWMyNDdkMDBfMTUwNzEzNjUxNjI5N182NjExXzc2OTgmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg
Or directly using the href information.
This response already is giving you the ID and URL to access all the info of a single place.
You don't need any other external ID or reference.
I'm quite confused by how to operate the changes API.
At the moment, I'm just making get requests:
https://www.googleapis.com/drive/v3/changes?access_token=**my_token**&pageToken=68485 **Last few additions to the list
I get:
{
"kind": "drive#changeList",
"newStartPageToken": "68489",
"changes": [
{
"kind": "drive#change",
"type": "file",
"time": "2017-04-08T00:40:36.141Z",
"removed": false,
"fileId": "***ID",
"file": {
"kind": "drive#file",
"id": "***ID",
"name": "***NAME",
"mimeType": "application/vnd.google-apps.folder"
}
},
{
"kind": "drive#change",
"type": "file",
"time": "2017-04-08T00:41:00.171Z",
"removed": false,
"fileId": "***ID2",
"file": {
"kind": "drive#file",
"id": "***ID2",
"name": "***NAME2",
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
]
I'm not aware of making changes to the first item in the changes array.
After playing around, I realised that every time a folder is opened it's added to the changes, why? Is it because the meta-data is being changes, i.e. last-accessed?
Does the same thing happen when files are previewed/opened/downloaded?
I trashed the second item in the array, yet it shows nothing about this.
How exactly am I to tell what is being changed. I'm trying to retrieve events such as file updates, creations, deletions etc.
The official properties that Changes uses which are found in the Changes resource representations:
{
"kind": "drive#change",
"type": string,
"time": datetime,
"removed": boolean,
"fileId": string,
"file": files Resource,
"teamDriveId": string,
"teamDrive": teamdrives Resource
}
Now this might not make a complete answer but I'd like to share some points.
Is it because the meta-data is being changes, i.e. last-accessed?
Yes, it is. It's a bit strange but yes, even previewing the file counts as a change. If you've closely watched the Drive's Android App, you can see that just viewing a photo will populate it under the "Recents" tab.
In API v2, there was even a files.touch() method, just for updating the last accessed time of a file!
How exactly am I to tell what is being changed?
There is a property named changes[] returned by changes.list() which is a list containing the changes. You could use this to determine if the change was relevant to you (like updation, creation, deletion) or ignore if it was just a preview.
To add to this, instead of continuously checking for changes, a more efficient way to detect changes is by using the changes.watch() method to subscribe for updates to the changes, which I hope you are already aware of.
And about trashing. Trashing doesn't really "change" a file in Drive. A trashed file is treated just like an ordinary file with the exception of having "Trashed" flag, which makes it directly invisible. Note that shared files are still accessible by collaborators, even if it's trashed. However, change should fire if the file is permanently deleted.
I am working with XBMC. I have installed XBMC in my system(Windows 7, 32 bit). Xbmc is working fine in my system. I have developed an application in order to control the Xbmc remotely from Ipad. In order to retrieve the music files or video files from Xbmc, I am unable to. By searching the forums of xbmc, I found that we can write an sql query to get them out. But, the thing is I am unable to make out where the database is located in my system. Someone help me out where I can find it.
Regards,
Sushma.
The database itself
By default the location of the database is that described on the wiki page XBMC databases
but the actual location can be changed by the user, or a different database technology can be used entirely.
The settings that would affect this are located in advancedsettings.xml.
But in general it is advised by the XBMC developers to never access the database directly.
JSONRPC
In order to help with interacting with the database XBMC has supported the JSONRPC queries, the one downside of these is that XBMC needs to be running at the time to respond to these queries. The major advantage is that it XBMC will find the database for you and expose access to it with a common interface.
JSONRPC support was first added to XBMC in "Darhma" (v10), became really useful in "Eden" (v11) and will support almost everything possible in "Frodo" (v12). Information about the use of JSONRPC can be found in the wiki.
An example
In this example I'm assuming that you are targeting "Eden", the current stable release of XBMC. Also I have formatted the following with new lines, these are not required and are not present in the response from XBMC.
Request
If you were to use JSONRPC the request you would need to send would look something like:
{
"jsonrpc": "2.0",
"method": "VideoLibrary.GetMovies",
"params": {
"properties": [
"title",
"year",
"file"
],
"limits": {
"start": 0,
"end": 2
}
},
"id": 1
}
Note: If you wanted different information about each movie you could use other properties listed here.
*Note: You probably want to omit the "limits" part to get all movies.*
Responce
The response to this would be something like:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"limits": {
"end": 2,
"start": 0,
"total": 47
},
"movies": [
{
"label": "Label for movie",
"movieid": 1,
"title": "Title of movie",
"year": 2012
},
{
"label": "Label for another movie",
"movieid": 2,
"title": "Title of another movie",
"year": 2010
},
{
"label": "Label for a third movie",
"movieid": 3,
"title": "Title of a third movie",
"year": 2012
}
]
}
}
What to do now?
You have a choice at this point, you can either:
Add "file" to the list of properties, this will return the "file" property, the location of the video file.
Use JSONRPC to tell xbmc to play a movie.
Using this method is best when you don't want to play the file locally (on the iPad) but instead on XBMC.
Playing a movie on XBMC via JSONRPC
This is quite simple, use the "movieid" you received earlier in the following request:
{
"jsonrpc": "2.0",
"method": "Player.Open",
"params": {
"item": {
"movieid": 2
}
},
"id": 1
}
Lastly I would note that there are equivalent commands for TV episodes as shown for movies.