web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

D365 F&O Web APIpassing parameters

(0) ShareShare
ReportReport
Posted on by 71

Currently I have SOAP calls into D365 F&O to retrieve and update data.   This is working correctly.

We have a concern with the longevity and performance of SOAP, so I am trying to convert the SOAP into Web API.  The SOAP calls into the AOT / X++ code, both our custom code and base D365 code for the data reads and updates.  We need to be able to maintain reading these code sets to maintain the use of business logic and not having to re-write the entire application.   I have copied the code below.

It is returning a response of:  

"Message": "An exception occured when deserializing a parameters - Exception occured when parsing the request content - Error reading JObject from JsonReader.
    Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.",
"ExceptionType": "XppServicesDeserializationException",
"ActivityId": "1b9ca4c9-b2ff-0004-68a9-9c1bffb2d801"

I have verified that postContentTest variable is a legit JSON object.

using (var clientWebAPI = CreateClient(DynamicsURI, AccessToken))
{
      var postContentTest = JsonConvert.SerializeObject(dataSources.ToArray());
      HttpContent postContent = new StringContent(JsonConvert.SerializeObject(dataSources.ToArray()), Encoding.UTF8, "application/json");
      var response = clientWebAPI.PostAsync(<method / procedure to call>, postContent);
      if (!response.Result.IsSuccessStatusCode)
            queryResultDataWebAPI = string.Empty;

      queryResultDataWebAPI = response.Result.Content.ReadAsStringAsync().Result;

}

private HttpClient CreateClient(string dynamicsURI, string AccessToken)
{
     var client = new HttpClient();
     client.BaseAddress = new Uri(dynamicsURI + "/api/services/");
     client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);

     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0");
     client.Timeout = TimeSpan.FromMinutes(30);
     return client;
}

Does the call need to be using XML instead of JSON since SOAP is XML based and we have not changed the D365 system?

What piece of am I missing in this puzzle?

Does anybody know for certain if SOAP is being removed from D365 F&O?  I'm seeing conflicting responses on web sites.

any assistance is appreciated.

Thanks

Duane.

I have the same question (0)
  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    It should be JSON. But not any "a legit JSON object" - it must a be a JSON object with properties that matches exactly the names of parameters of the method exposed as a custom service. And it must have the right structure.

    It seems to me that you're passing an array instead of an object.

  • DDMoore Profile Picture
    71 on at

    Should have also shown the receiving method.  It's expecting a list.  The list is read and a query is created and executed.

    public str ExecuteQuery(List QueryDataSources, boolean _crossCompany = false)

    {

       <code>

    }

    I am also receiving the same response exception using Postman.

  • Suggested answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    This custom service is expecting a JSON with two properties - one called QueryDataSources and the other called _crossCompany.

    By the way, I would avoid the optional parameter - I would rather expect that it's not supported by custom services.

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    May I have your JSON Structure and also what result you get using a get API call?

    Thanks

  • DDMoore Profile Picture
    71 on at

    Here's the JSON that's being sent into D365:

    { "_SWXQueryDataSources": {

           "selectFields": [

             {

               "getSelectionType": 5,

               "getfieldName": "name"

             },

             {

               "getSelectionType": 5,

               "getfieldName": "value"

             },

             {

               "getSelectionType": 5,

               "getfieldName": "RecId"

             }

           ],

           "groupByFields": [],

           "orderByFields": [],

           "dataRanges": [],

           "dataLinks": [],

           "selectForUpdate": false,

           "firstRecordOnly": false,

           "selectAllFields": false,

           "tableName": "ScanWorkX_CoreParameters",

           "joinMode": 0,

           "sortOrder": 0

       },

       "_crossCompany": false  

     }

    I'm past the original error message, had an extra "[" at the beginning.  Now receiving the error message - received using Postman.

    "Message": "An exception occured when deserializing a parameters - Exception occurred when parsing and deserializing parameter '_SWXQueryDataSources' - 'Error while deserializing contract class'",

       "ExceptionType": "XppServicesDeserializationException",

       "ActivityId": "f8d236e9-b3c8-0003-0f42-d2f8c8b3d801"

    I have another request which has a single string value in it, which is working as expected.   My thought at this point is the an issue with one of the JSON attributes which does not allow the JSON string to be converted into the list object.

    Any additional thoughts or suggestions will be appreciated.

    Thanks for the help.

    Duane

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    Please use Insert > Code to paste code, including JSON:

    {
    	"_SWXQueryDataSources": {
    		"selectFields": [
    			{
    				"getSelectionType": 5,
    				"getfieldName": "name"
    			},
    			{
    				"getSelectionType": 5,
    				"getfieldName": "value"
    			},
    			{
    				"getSelectionType": 5,
    				"getfieldName": "RecId"
    			}
    		],
    		"groupByFields": [],
    		"orderByFields": [],
    		"dataRanges": [],
    		"dataLinks": [],
    		"selectForUpdate": false,
    		"firstRecordOnly": false,
    		"selectAllFields": false,
    		"tableName": "ScanWorkX_CoreParameters",
    		"joinMode": 0,
    		"sortOrder": 0
    	},
    	"_crossCompany": false  
    }

    Please notice that first property that your method expects is called QueryDataSources, but the name in your JSON is called _SWXQueryDataSources instead.

    Also, the expected type of QueryDataSources is an array, while your JSON passes an object for _SWXQueryDataSources. Your method declaration should also specify the type of elements of the List - use AifCollectionType attribute to do that. Or, if you really want to use an object instead of an array, fix the data type of the parameter. You should use a data contract class there is such a case.

  • DDMoore Profile Picture
    71 on at

    Thanks for the assistance.   The issue with the QueryDataSources instead of _SWXQueryDataSources was a typo on my part in this discussion.   When the JSON was not _SWXQueryDataSources it caused an error like missing variable definition of _SWXQueryDataSources.

    Your second comment about an object instead of an array was the issue.   Made the necessary changes and I'm receiving the expected data returned.  

    Thanks again.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans