title: Microsoft Dynamics 365 Field Service Web API: Create a work order triggers a "code": "0x80040265", "message": "The Service Account is required.",
body: <h1>HTTP POST to create a new Work Order in Microsoft Dynamics 365 - Field Service (Empty body)</h1>
  <pre><code>import requests
  
  url = &quot;https://{{my-env_name}}.{{my_region}}.dynamics.com/api/data/v9.0/msdyn_workorders&quot;
  
  payload = &quot;{\n   \n}&quot;
  headers = {
    'Accept': 'application/json',
    'OData-MaxVersion': '4.0',
    'OData-Version': '4.0',
    'If-None-Match': 'null',
    'Authorization': 'Bearer eyXXX',
    'Content-Type': 'application/json',
  }
  
  response = requests.request(&quot;POST&quot;, url, headers=headers, data = payload)
  
  print(response.text.encode('utf8'))
  
  
  </code></pre>
  <h1>Error received when the Body of the POST is empty</h1>
  <pre><code>{
      &quot;error&quot;: {
          &quot;code&quot;: &quot;0x80040265&quot;,
  
          &quot;message&quot;: &quot;The Service Account is required.&quot;,
  
          &quot;innererror&quot;: {
              &quot;message&quot;: &quot;The Service Account is required.&quot;,
  
              &quot;type&quot;: &quot;System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]&quot;,
  
              &quot;stacktrace&quot;: &quot;   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.CreateInternal(Entity entity, InvocationContext invocationContext, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, Dictionary`2 optionalParameters)\r\n
  
     at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.CreateOrganizationResponse(Entity entity)\r\n
  
     at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.CreateEdmEntity(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)\r\n
  
     at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySetImplementation(String&amp; entitySetName, EdmEntityObject entityObject)\r\n
  
     at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.&lt;&gt;c__DisplayClass10_0`2.&lt;InvokeActionAndLogMetric&gt;b__0()\r\n
  
     at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n
  
     at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n
  
     at lambda_method(Closure , Object , Object[] )\r\n
  
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass10.&lt;GetExecutor&gt;b__9(Object instance, Object[] methodParameters)\r\n
  
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n
  
  --- End of stack trace from previous location where exception was thrown ---\r\n
  
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
     at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()\r\n
  
  --- End of stack trace from previous location where exception was thrown ---\r\n
  
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__2.MoveNext()\r\n
  
  --- End of stack trace from previous location where exception was thrown ---\r\n
  
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()&quot;
          }
      }
  }
  </code></pre>
  <h1>I add the Service Account into the body of the POST</h1>
  <p>Look at the model of a Work Order : <a href="https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/msdyn_workorder?view=dynamics-ce-odata-9" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/msdyn_workorder?view=dynamics-ce-odata-9</a></p>
  <pre><code>{
    &quot;msdyn_serviceaccount&quot;: &quot;{{an existing account id}}&quot;
  }
  
  </code></pre>
  <h1>Error received when the Body of the POST contains the msdyn_serviceaccount field</h1>
  <pre><code>{
      &quot;error&quot;: {
  
          &quot;code&quot;: &quot;0x0&quot;,
  
  
          &quot;message&quot;: &quot;An error occurred while validating input parameters: Microsoft.OData.ODataException: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'msdyn_serviceaccount'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, Nullable`1 isCollection, String propertyName)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.&lt;&gt;c__DisplayClass9_0.&lt;ReadResourceContent&gt;b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n   at 
  
  Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n 
  
    at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n
  
     at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n
  
     at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n
  
     at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n
  
     at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)&quot;,
          &quot;innererror&quot;: {
  
              &quot;message&quot;: &quot;An error occurred while validating input parameters: Microsoft.OData.ODataException: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'msdyn_serviceaccount'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, Nullable`1 isCollection, String propertyName)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.&lt;&gt;c__DisplayClass9_0.&lt;ReadResourceContent&gt;b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n
  
     at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n
  
     at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n
  
     at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n
  
     at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n
  
     at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n
  
     at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)&quot;,
              &quot;type&quot;: &quot;Microsoft.Crm.CrmHttpException&quot;,
              &quot;stacktrace&quot;: &quot;   at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidateInputParameters(ModelStateDictionary controllerModelState)\r\n
  
     at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySetImplementation(String&amp; entitySetName, EdmEntityObject entityObject)\r\n
  
     at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.&lt;&gt;c__DisplayClass10_0`2.&lt;InvokeActionAndLogMetric&gt;b__0()\r\n
  
     at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n
  
     at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n
  
     at lambda_method(Closure , Object , Object[] )\r\n
  
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass10.&lt;GetExecutor&gt;b__9(Object instance, Object[] methodParameters)\r\n
  
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
  
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
  
     at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()\r\n
  
  --- End of stack trace from previous location where exception was thrown ---\r\n
  
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
  
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
  
     at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__2.MoveNext()\r\n
  
  --- End of stack trace from previous location where exception was thrown ---\r\n
  
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
  
     at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()&quot;
          }
      }
  }
  </code></pre>
  <h1>QUESTION: What is the expected JSON body by the Web API of Microsoft Dynamics 365 Field Service?</h1>