dynamicweb / CLI

CLI for Dynamicweb 10 automation in development, builds and deployment scenarios
4 stars 2 forks source link

Cannot delete a page using the PageDelete command #10

Closed Imar closed 2 years ago

Imar commented 2 years ago

I am trying to delete a page using the following command:

dw command PageDelete --id 1714

Expected results The page is deleted

Actual results: An error is displayed at the console: Error when doing request https://localhost:44360/Admin/Api/PageDelete?Command.id=1714 { status: 'error', message: 'The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.', exception: 'System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.\r\n' + ' ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.\r\n' + ' at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes)\r\n' + ' at System.Text.Json.Utf8JsonReader.Read()\r\n' + ' at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)\r\n' + ' --- End of inner exception stack trace ---\r\n' + ' at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)\r\n' + ' at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)\r\n' + ' at System.Text.Json.Serialization.JsonConverter1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)\r\n' + ' at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable1 actualByteCount)\r\n' + ' at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)\r\n' + ' at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)\r\n' + ' at Dynamicweb.Management.Api.Controllers.Api.DataController.GetCommandResult(Type commandType, Type queryType, Object body)\r\n' + ' at Dynamicweb.Management.Api.Controllers.Api.DataController.Post(String command, Object body)', model: null, modelIdentifier: null, resultActions: [] }

frederik5480 commented 2 years ago

Readme has been updated to reflect the proper example for page delete, these query properties has been moved into the json model being sent to the management API, as this is a property directly tied to the command, it will be in the root of the object sent and not part of 'model'.

Imar commented 2 years ago

It seems that the JSON command doesn't like the JSON at the command prompt. Executing this:

dw command PageDelete --json '{ "Id": "1714" }'

Now gives me this:

SyntaxError: Unexpected token ' in JSON at position 0 at JSON.parse () at parseJsonOrPath (file:///D:/Projects/Dynamicweb/Cli/bin/commands/command.js:75:21) at handleCommand (file:///D:/Projects/Dynamicweb/Cli/bin/commands/command.js:44:88)

It works when I use double quotes on the command line and escape the ones in the JSON:

dw command PageDelete --json "{ \"Id\": \"1718\" }"

This also fails in PowerShell where I have to use single quotes around the command and escaped double quotes within:

dw command PageDelete --json '{ \"Id\": \"1722\" }'