I do have a C# example but it's a basic ServiceStack Auth provider against Umbraco back office and once authenticated has no further interaction with Umbraco, hence posting Powershell example.
Unsure why Umbraco returns the JSON starting with )]}',; I parse it before converting from JSON to a POCO.
var restClient = new RestClient(Settings.UmbracoUrl);
var request = new RestRequest(String.Format("{0}/content/createorupdate", Settings.RestApiUrl));
request.AddHeader("Authorization", "Bearer " + _umbracoAccessToken);
request.Method = Method.POST;
var body = JsonConvert.SerializeObject(content);
request.AddParameter("application/json", body, ParameterType.RequestBody);
var response = restClient.Execute(request);
I did yeah, but it seems unfinished and has limited configuration. I have to add authentication to harden up existing API calls so I cannot use the rest routes.
I'm amazed that this isn't something I cannot easily do out of the box.
Yeah you might be surprised how far you'd get with it. Some are unfinished (e.g. remove content). There is authentication built in with backoffice users so that helps.
Authenticating requests from external sources.
Using Umbraco 7.4.3
I have a client that want to edit CMS data without navigating to the site and logging in.
What's the best way to authenticate a POST request to the CMS and what format should the credentials be given in when making that request?
A code sample would be really useful if you can, this task has come up with very tight time constraints and I've hit a blank spot in my knowledge.
Cheers
James
Have done similar to fire off tasks from Powershell.
Posting a rough no error checking Powershell example that authenticates then get's remaining timeout, may help with at least authenticating.
I do have a C# example but it's a basic ServiceStack Auth provider against Umbraco back office and once authenticated has no further interaction with Umbraco, hence posting Powershell example.
Unsure why Umbraco returns the JSON starting with
)]}',
; I parse it before converting from JSON to a POCO.The reason for the prefix on the response is for security matters, read the security considerations here: https://code.angularjs.org/1.5.7/docs/api/ng/service/$http
Thanks for the example.
Odd that you are sending the username/password via json. I won't be able to get my client to replicate that.
Hey James - have you considered the Umbraco Rest API?
https://github.com/umbraco/UmbracoRestApi
Some Code:
Hi Alan,
I did yeah, but it seems unfinished and has limited configuration. I have to add authentication to harden up existing API calls so I cannot use the rest routes.
I'm amazed that this isn't something I cannot easily do out of the box.
Cheers
James
Yeah you might be surprised how far you'd get with it. Some are unfinished (e.g. remove content). There is authentication built in with backoffice users so that helps.
Best
is working on a reply...