Example #1
0
        /// <summary>
        /// Append to the default outline in the content of an existing page
        /// </summary>
        /// <param name="debug">Run the code under the debugger</param>
        /// <param name="pageId">The identifier of the page whose content to append to</param>
        /// <param name="provider"></param>
        /// <param name="apiRoute"></param>
        /// <remarks>Create page using a single part text/html content type</remarks>
        /// <returns>The converted HTTP response message</returns>
        public static async Task <ApiBaseResponse> AppendToDefaultOutlineInPageContent(bool debug, string pageId, AuthProvider provider, string apiRoute)
        {
            if (debug)
            {
                Debugger.Launch();
                Debugger.Break();
            }

            var client = new HttpClient();

            // Note: API only supports JSON response.
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // Not adding the Authentication header would produce an unauthorized call and the API will return a 401
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
                                                                                       await Auth.GetAuthToken(provider));

            //The request content must be a JSON list of commands
            var commands = new List <PatchCommand>();

            //Each command must contain atleast a target and an action. Specifying content may be optional or mandatory depending on the action specified.
            var appendCommand = new PatchCommand();

            appendCommand.Target = "body";
            //While in this case the PATCH action is append, the API supports replace (to replace existing page content) and insert (insert new page content relative to existing content) actions as well.
            appendCommand.Action  = "append";
            appendCommand.Content = "<p>New trailing content</p>";

            commands.Add(appendCommand);

            var appendRequestContent = JsonConvert.SerializeObject(commands);

            // Prepare an HTTP PATCH request to the Pages/{pageId}/content endpoint
            // The request body content type is application/json
            var createMessage = new HttpRequestMessage(new HttpMethod("PATCH"), apiRoute + "pages/" + pageId + "/content")
            {
                Content = new StringContent(appendRequestContent, Encoding.UTF8, "application/json")
            };

            HttpResponseMessage response = await client.SendAsync(createMessage);

            return(await TranslatePatchResponse(response));
        }
		/// <summary>
		/// Append to the default outline in the content of an existing page
		/// </summary>
		/// <param name="debug">Run the code under the debugger</param>
		/// <param name="pageId">The identifier of the page whose content to append to</param>
		/// <param name="provider"></param>
		/// <param name="apiRoute"></param>
		/// <remarks>Create page using a single part text/html content type</remarks>
		/// <returns>The converted HTTP response message</returns>
		public static async Task<ApiBaseResponse> AppendToDefaultOutlineInPageContent(bool debug, string pageId, AuthProvider provider, string apiRoute)
		{
			if (debug)
			{
				Debugger.Launch();
				Debugger.Break();
			}
			
			var client = new HttpClient();

			// Note: API only supports JSON response.
			client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

			// Not adding the Authentication header would produce an unauthorized call and the API will return a 401
			client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
				await Auth.GetAuthToken(provider));

			//The request content must be a JSON list of commands
			var commands = new List<PatchCommand>();

			//Each command must contain atleast a target and an action. Specifying content may be optional or mandatory depending on the action specified.
			var appendCommand = new PatchCommand();
			appendCommand.Target = "body";
			//While in this case the PATCH action is append, the API supports replace (to replace existing page content) and insert (insert new page content relative to existing content) actions as well.
			appendCommand.Action = "append";
			appendCommand.Content = "<p>New trailing content</p>";

			commands.Add(appendCommand);

			var appendRequestContent = JsonConvert.SerializeObject(commands);

			// Prepare an HTTP PATCH request to the Pages/{pageId}/content endpoint
			// The request body content type is application/json
			var createMessage = new HttpRequestMessage(new HttpMethod("PATCH"), apiRoute + "pages/" + pageId + "/content")
			{
				Content = new StringContent(appendRequestContent, Encoding.UTF8, "application/json")
			};

			HttpResponseMessage response = await client.SendAsync(createMessage);

			return await TranslatePatchResponse(response);
		}