Umbraco V8 uSync trigger import via url or api endpoint
Hi All,
I wondered if there was some way of triggering uSync import via a public url or if not is there an API I could use to create my own endpoint to do this?
What I am trying to achieve is adding a Url to my deployment script.
The idea is once I've done a deployment I would trigger a url which would then automatically run the update.
I understand there are some settings to set this going at start up but I don't really want to do this every time there is an IIS restart etc. I would be great if I could just trigger this the once without having to log into the backend and trigger this manually.
public IEnumerable<uSyncAction> Import(uSyncOptions options)
{
var hubClient = new HubClientService(options.ClientId);
return uSyncService.Import(settings.RootFolder, options.Force, new SyncHandlerOptions()
{
Group = options.Group
},
callbacks: hubClient.Callbacks());
}
of the options here:
callbacks can be null, its uses as part of the signalR UI updating - not needed
group can also be omitted (so it becomes new SyncHandlerOptions()) group lets you only sync either settings ,or content - if omitted it does all
force : if true everything is imported even if it hasn't changed - this is much slower, so unless you have a real reason, force = false.
I would personally put some authentication around that (maybe a shared key/id or something in the api call?).
Thanks for getting back to me so quickly.
Some good solutions.
Kevin I was actually thinking the same. I sort of found this endpoint in the packages folder in one of the angularJs files. I was planning on jumping on the top of that. But yeah I was unsure what the options were.
Thanks for explaining.
I get you about the public URL. I was thinking the same. I would create some kind of auth. Even if just an encrypted query string or something.
Do you know where I might find the client Id?
I think this is the only bit I am unsure about.
you don't need the clientId it is the internal id signalR uses when connecting to a browser to send messages - so unless you have a signalR end point you want to get the update messages for, you can choose not to create the hub and pass null for the callbacks.
What I probably wasn't clear about is that usync.once file is added as part of the deployment. So no messing about having to remember to add this file to sourcecode, just create it in your deployment script - it's so simple I forgot we'd even did it.
I think you're over complicating things with API calls.. unless I'm missing something complicated about your setup? When you do a deployment you'd want your usync changes to run on startup before your new code starts firing...?
public IEnumerable<uSyncAction> Import(uSyncOptions options)
{
var hubClient = new HubClientService(options.ClientId);
return uSyncService.Import(settings.RootFolder, options.Force, new SyncHandlerOptions()
{
Group = options.Group
},
callbacks: hubClient.Callbacks());
} of the options here:
callbacks can be null, its uses as part of the signalR UI updating -
not needed group can also be omitted (so it becomes new
SyncHandlerOptions()) group lets you only sync either settings ,or
content - if omitted it does all force : if true everything is
imported even if it hasn't changed - this is much slower, so unless
you have a real reason, force = false. I would personally put some
authentication around that (maybe a shared key/id or something in the
api call?).
I got really good information from this content. thanks for sharing.
Umbraco V8 uSync trigger import via url or api endpoint
Hi All,
I wondered if there was some way of triggering uSync import via a public url or if not is there an API I could use to create my own endpoint to do this?
What I am trying to achieve is adding a Url to my deployment script. The idea is once I've done a deployment I would trigger a url which would then automatically run the update.
I understand there are some settings to set this going at start up but I don't really want to do this every time there is an IIS restart etc. I would be great if I could just trigger this the once without having to log into the backend and trigger this manually.
Thanks in advanced.
Kind Regards
David
Hi David,
What I've done successfully in the past is to add a usync.stop file after the deployment is successful.
Then your lovely usync changes are imported but for future restarts the site skips any overhead.
It's just a simple text file in the usync directory. Worked a treat!
HTH
Steve
There was also usync.once - add this and it runs once and renames to .stop
https://github.com/KevinJump/uSync/issues/29
I think this is still in the current version.
As Steve says usync.once will do a single sync, so you can have it happen only the first time.
There is no public (unauthenticated) end point, (you don't want random's resyncing your site!). but you could add one,
You could take code for the authenticated API controller (the one the dashboard uses). and put this in your own controller. ?
https://github.com/KevinJump/uSync8/blob/v8/8.7-main/uSync8.BackOffice/Controllers/uSyncDashboardApiController.cs#L127
of the options here:
new SyncHandlerOptions()
) group lets you only sync either settings ,or content - if omitted it does allI would personally put some authentication around that (maybe a shared key/id or something in the api call?).
Hey Guys,
Thanks for getting back to me so quickly. Some good solutions.
Kevin I was actually thinking the same. I sort of found this endpoint in the packages folder in one of the angularJs files. I was planning on jumping on the top of that. But yeah I was unsure what the options were.
Thanks for explaining.
I get you about the public URL. I was thinking the same. I would create some kind of auth. Even if just an encrypted query string or something.
Do you know where I might find the client Id? I think this is the only bit I am unsure about.
Thanks again.
David
Hi,
you don't need the clientId it is the internal id signalR uses when connecting to a browser to send messages - so unless you have a signalR end point you want to get the update messages for, you can choose not to create the hub and pass null for the callbacks.
if you do want signalR - well it gets complex but uSync's code is here. https://github.com/KevinJump/uSync8/blob/v8/8.7-main/uSync8.BackOffice/App_Plugins/uSync8/settings/uSyncController.js#L337
and a slightly tidier implimentation for reference is here. https://github.com/KevinJump/DoStuffWithUmbraco/tree/master/Src/DoStuff.Core/SignalR
Perfect. I will give this a go.
Thanks Kevin, Steve
What I probably wasn't clear about is that usync.once file is added as part of the deployment. So no messing about having to remember to add this file to sourcecode, just create it in your deployment script - it's so simple I forgot we'd even did it.
I think you're over complicating things with API calls.. unless I'm missing something complicated about your setup? When you do a deployment you'd want your usync changes to run on startup before your new code starts firing...?
And, as usual, great stuff from Kevin here.
Steve
Hi Steve,
In that case your solution sounds great. If its just a point of adding this into the deployment then that is fine.
I will also give this a go.
Thanks - not really my solution. It's Kevin's - he built the logic after all :)
As S
I got really good information from this content. thanks for sharing.
Read more
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.