Powershell Invoke-RestMethod to insert a new customer

jordi79jordi79 Member Posts: 230
I am trying to insert a new customer using PowerShell via Odata.
#Create new Customer
$Credential = [System.Management.Automation.PSCredential]::new('USERNAME',(ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force))
$Payload = 
        ""No"" : ""TEST10001"",
        ""Name"" : ""Test asdfgh""


$obj1 = 
    Invoke-RestMethod `
        -uri "https://NAVSERVERNAME:7048/NAVSERVERINSTANCE/ODatav4/Company('COMPANYNAME')/Customer?tenant=TENANTNAME$format=json" `
        -Method Post `
        -Body $Payload `
        -Credential $Credential `
        -ContentType "application/json"

But I get this error:
Invoke-RestMethod : The remote server returned an error: (406) Not Acceptable.

What am I doing wrong?

Also, what about modifying a record via Odata?
Sign In or Register to comment.