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 :
Small and medium business | Business Central, N...
Answered

BadRequest error returned posting customer via BC API

(0) ShareShare
ReportReport
Posted on by 20

I'm trying to create a customer with the following URL and data and receiving the followig error.

Error:

{"error":{"code":"BadRequest","message":"Invalid Request Body  CorrelationId:  6f64a809-4a74-4bbb-a2a7-73349b923dee."}}

Endpoint:

api.businesscentral.dynamics.com/.../customers

Data:

{
"number": "TEST1000",
"displayName": "Test Customer",
"type": "Company",
"addressLine1": "",
"addressLine2": "",
"city": "",
"state": "",
"country": "",
"postalCode": "",
"phoneNumber": "",
"email": "",
"website": "",
"salespersonCode": "",
"balanceDue": 0,
"creditLimit": 0,
"taxLiable": false,
"taxAreaId": <taxAreaId-guid>,
"taxAreaDisplayName": "",
"taxRegistrationNumber": "",
"currencyId": "00000000-0000-0000-0000-000000000000",
"currencyCode": "USD",
"paymentTermsId": <paymentTermsId-guid>,
"shipmentMethodId": "00000000-0000-0000-0000-000000000000",
"paymentMethodId": "00000000-0000-0000-0000-000000000000"
}

To get the data in my customer, I manually created one in the app, retrieved that data with the api and changed the number and displayName,

I also removed fields:       "@odata.etag",  "id", "blocked", and "lastModifiedDateTime"

Any help would be appreciated.

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

    I have tried to re-produce the data you had shared.

    Below is the correct body I used and its working my side

    {
    "number": "TEST1000",
    "displayName": "Test Customer",
    "type": "Company",
    "addressLine1": "",
    "addressLine2": "",
    "city": "",
    "state": "",
    "country": "",
    "postalCode": "",
    "phoneNumber": "",
    "email": "",
    "website": "",
    "salespersonCode": "",
    "creditLimit": 0,
    "taxLiable": false,
    "taxRegistrationNumber": "",
    "currencyId": "00000000-0000-0000-0000-000000000000",
    "currencyCode": "USD",
    "shipmentMethodId": "00000000-0000-0000-0000-000000000000",
    "paymentMethodId": "00000000-0000-0000-0000-000000000000"
    }
  • Pat Arneson Profile Picture
    20 on at

    Getting the same error with that data. Perhaps I'm missing something else? What's in your request header?

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Are you using POST method and

    pastedimage1677119376959v1.png

  • Pat Arneson Profile Picture
    20 on at

    Same. I don't get it.

    Could it be that I have a permissions problem or perhaps don't have the setting correct for auto generating the id guid?

    I'm kind of at a loss.

  • Pat Arneson Profile Picture
    20 on at

    I didn't see the first part of that. Yes I'm using the POST method and have the Content-Type in my header.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Can you try with GET method first? and check if you are getting the customer list.

  • Pat Arneson Profile Picture
    20 on at

    Yes, I've successfully gotten a customer list and queried on a specific number using a filter.

  • Pat Arneson Profile Picture
    20 on at

    URLs I'm using. These work fine as get requests.

    url = f"api.businesscentral.dynamics.com/.../customers"

    url = f"api.businesscentral.dynamics.com/.../customers eq '{customer_number}'"

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    share me everything what you are using

  • Pat Arneson Profile Picture
    20 on at

    Here's my python code:

    import msal

    import logging

    import json

    import requests

    customer_id = 'removed'

    def acquire_token():

       config = json.load(open("parameters.json"))

       app = msal.ConfidentialClientApplication(

           config["client_id"], authority=config["authority"],

           client_credential=config["secret"],

       )

       result = None

       result = app.acquire_token_silent(config["scope"], account=None)

       if not result:

           logging.info("No suitable token exists in cache. Let's get a new one from AAD.")

           result = app.acquire_token_for_client(scopes=config["scope"])

       return result['access_token']

    class Customer:

       json = ""

       def __init__(self, json):

           self.json = json

           print(self.json)

       @staticmethod

       def get_customers():

           access_token = acquire_token()

           url = f"api.businesscentral.dynamics.com/.../customers"

           result = requests.get(

               url,

               headers={'Authorization': 'Bearer ' + access_token}, )

           print("gd: %s" % result)

           result_json = result.json()

           print("Graph API call result: ")

           print(json.dumps(result_json, indent=2))

       @staticmethod

       def query_customer(customer_number):

           access_token = acquire_token()

           url = f"api.businesscentral.dynamics.com/.../customers eq '{customer_number}'"

           result = requests.get(

               url,

               headers={'Authorization': 'Bearer ' + access_token}, )

           print("status: %s" % result.status_code)

           result_json = result.json()

           print("result data: ")

           print(json.dumps(result_json, indent=2))

       @classmethod

       def create_customer(cls):

           print(cls.json)

           access_token = acquire_token()

           url = f"api.businesscentral.dynamics.com/.../customers"

           result = requests.post(

               url,

               data=cls.json,

               headers={'Authorization': 'Bearer ' + access_token, 'Content-type': 'application/json',

                        'Content-Length': str(len(cls.json))}, )

           print("status: %s" % result.status_code)

           print("messsage: %s" % result.text)

    Customer.get_customers()

    Customer.query_customer("WHATEVAH")

    customer = Customer(open('test_customer.json').read())

    customer.create_customer()

    And the current contents of my data file:

    {

    "number": "TEST1000",

    "displayName": "Test Customer",

    "type": "Company",

    "addressLine1": "",

    "addressLine2": "",

    "city": "",

    "state": "",

    "country": "",

    "postalCode": "",

    "phoneNumber": "",

    "email": "",

    "website": "",

    "salespersonCode": "",

    "creditLimit": 0,

    "taxLiable": false,

    "taxRegistrationNumber": "",

    "currencyId": "00000000-0000-0000-0000-000000000000",

    "currencyCode": "USD",

    "shipmentMethodId": "00000000-0000-0000-0000-000000000000",

    "paymentMethodId": "00000000-0000-0000-0000-000000000000"

    }

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans