public async Task <bool> CreatePageRule(string targetDomain, string urlToMatch, string forwardingUrl) { var zoneId = await ResolveZone(targetDomain); var createVm = new CreatePageRuleVM { Actions = new List <ActionResultType> { new ActionResultType { Id = "forwarding_url", Value = new ActionResultType.ValueResultType { Url = forwardingUrl, StatusCode = 301 } } }, Targets = new List <TargetResultType> { new TargetResultType { Constraint = new TargetResultType.ConstraintType { Operator = "matches", Value = urlToMatch }, Target = "url" } } }; // The replacement here is hacky, but I can't get Json.NET to do it the "right" way. var json = JsonConvert.SerializeObject(createVm).Replace("/", "\\/"); var response = await PerformWebRequest <ApiResponseVM>($"{API_ENDPOINT}/zones/{zoneId}/pagerules", HttpMethod.Post, json); return(response.Success); }
public async Task <bool> EditPageRule(string targetDomain, string urlToMatch, string forwardingUrl, string id) { var zoneId = await ResolveZone(targetDomain); var editVm = new CreatePageRuleVM { Actions = new List <ActionResultType> { new ActionResultType { Id = "forwarding_url", Value = new ActionResultType.ValueResultType { Url = forwardingUrl, StatusCode = 301 } } }, Targets = new List <TargetResultType> { new TargetResultType { Constraint = new TargetResultType.ConstraintType { Operator = "matches", Value = urlToMatch }, Target = "url" } } }; var json = JsonConvert.SerializeObject(editVm).Replace("/", "\\/"); var result = await PerformWebRequest <ApiResponseVM>($"{API_ENDPOINT}/zones/{zoneId}/pagerules/{id}", new HttpMethod("PATCH"), json); return(result.Success); }