KelvinTegelaar / AutotaskAPI

Autotask 2020.2 REST API PowerShell wrapper

Home Page:https://cyberdrain.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Getting error codes when creating a company

CHHof opened this issue · comments

commented

Describe the bug
We have several thousand customers in our database that I want to sync with your Powershell REST API to our new Autotask PSA.
I worked on a script the last days (completely new to PowerShell, so I need a little bit ramp up time ;) ) to get the data out of the MS SQL database, put it into an Autotask body and make sure I don't sync duplicates when running the script several times (created a dummy customer via Web UI and changed it a few times to match against my script).

Finally I was sure that I am ready to sync a new customer and tried it with one dataset but when I use New-AutotaskAPIResource I get the error message:
"An unexpected error has occurred. If the problem persists, please contact Autotask Support and reference Error ID: 1166" Sometimes I also get 1165 as error ID with the same text.

I already checked:

  • If the Webservice URI is correct -> It is. Simple Gets are fine
  • If the API user has the correct permissions. It has API system rights and access to all things I can select

To Reproduce
I created the Autotaskbody (with NoContent parameter), filled the variables with the values from the database and then handed it over to New-AutotaskAPIResource.
Specific code:
$CompanyBody = New-AutotaskBody -Resource Companies -NoContent

  #Definition der Werte
  [string]$CompanyName = $customerresult.CUSTOMER_NAME
  [int16]$CompanyType = 1
  [int]$OwnerResourceID = 29682885
  [string]$PhoneNo = $mainadressresult.PHONE_NO
  [string]$Address1 = $mainadressresult.ADDRESS_2
  [string]$PostalCode = $mainadressresult.POSTAL_CODE
  [string]$City = $mainadressresult.DESCRIPTION
  [string]$WebAdress = $customerresult.http
  [string]$CompanyNumber = $customerresult.CUSTOMER_NO
  [long]$autotaskcustomerid = $customerresult.CUSTOMER_NO
  [int]$taxregion = 2


  #ID gleich der Kundennummer setzen
  #$CompanyBody.ID = $autotaskcustomerid
  #Firmennamen eintragen
  $CompanyBody.CompanyName = $CompanyName
  #CompanyType auf 1 setzen, das steht für Kunde (kein Interessent)
  $CompanyBody.CompanyType = $CompanyType
  #Zuständiger Mitarbeiter wird hinterlegt, als Dummy immer beim Import der "Autotask Administrator"
  $CompanyBody.OwnerResourceID = $OwnerResourceID
  #Telefonnummer OHNE Durchwahl
  $CompanyBody.Phone = $PhoneNo
  #Adresse hinterlegen (Straße, PLZ, Ort)
  $CompanyBody.Address1 = $Address1
  $CompanyBody.PostalCode = $PostalCode
  $CompanyBody.City = $City
  #Webseite hinterlegen
  $CompanyBody.WebAddress = $WebAdress
  #Firmennummer wird mit der Kundennummer für unique identifier gesetzt
  $CompanyBody.CompanyNumber = $CompanyNumber
  #Taskfire im Standard auf False setzen
  $CompanyBody.isTaskFireActive = $false
  #Steuerregion auf Deutschland setzen
  $CompanyBody.TaxRegionID = $taxregion
  #Wir müssen noch die benutzerdefinierten Felder setzen, damit die Evatic Kundennummer erkennbar ist, vorher muss der Kunde erstellt werden und dann die ID wieder ausgelesen werden über den unique identifier der Firmennummer
  #Wird erstmal nicht gesetzt, aber die Zeile bleibt drin weil die Syntax nicht ganz easy ist
  #Get-AutotaskApiResource -id 0 -resource companies | foreach-object {($_.UserDefinedFields | where-object {$_.name -eq "Evatic Kundennummer"}).value = $kundenid;$_} | Set-AutotaskApiResource -Resource Companies
  #echo "Ich würde den Kunden jetzt wie folgt anlegen"
  #echo $companybody

  New-AutotaskAPIResource -Resource Companies -Body $CompanyBody
  echo $Error

Expected behavior
I expect that the creation is successful.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • PowerShell version: V5.1
  • ScriptVersion: 1.1.1

If I can give any further information, please let me know.. I am afraid that Autotask did changes to the API so sth does not work anymore.

Regards,
Christian

You most likely are missing some required UDFs, To check, grab a company that you would like to copy and check which fields are filled in and which are not. Sorry for the late reply!

Duplicate of #26. Let's use that one instead. :)