API for Dynamics SL

How to add and edit SOAddress records in SL using Catalina’s API for Dynamics SL

Here is an example of how you can create a NEW shipto address, using POST, for a customer (NOTE:  I am doing a post and not passing a ShipToId in the URL.)

Also NOTE:  When doing a post (adding a NEW address), if you explicitly set a ShipToId in the body, it cant be an existing ShipToId for that customer or an error will be thrown.  If you do pass a ShipToId in the body, the system will try to create a new ShipTo Address using that ShipToId.  If you don’t pass a ShipToId, the API will auto generate a new ShipToId for you.

Another NOTE:  There is an issue with the API, where you need to make sure that you put the CustId in the body, when doing a POST for a new ShipTo Address, or it wont save against the CustId.  This is a known issue where the API doesn’t grab the CustId from the query string when it is saving the SOAddress, it grabs from the body.  So, make sure that you are putting CustId in the body (also NOTE the capitalization of CustId. Darn Solomon in its differences in capitalization throughout.)

Creating a new SOAddress for a customer:

Here is an example of how to create a new SOAddress using curl and the action type of POST.  Variables that are in the call:

  • yourserver:  You would replace the actual server you have the Catalina API installed on instead of using “yourserver.”  this is just a placeholder.
  • YOURAUTHCODEHERE:  This should be the encoded basic authentication string for your setup
  • YOURCPNYID:  This should be the CpnyID of the Company you are using from your System database
  • YOURSITEIDHERE:  This should be the SiteID setup in the API configuration
  • CUSTID1:  This is a customer ID (CustID) that I am using in my example.  You would of course use a valid CustID in your SL’s Customer table
  • ADDR1:  I am forcing this to save a new ShipTo Address with the ShipToId of “ADDR1”.  If ADDR1 already exists for this customer, it will throw an error.  NOTE:  You can leave this field out and the API will auto-generate an ID for you
  • Other fields in the body is data that I wanted to save in the SOAddress
Curl -x post \
http://yourserver/ctdynamicssl/api/financial/accountsreceivable/customer/c300/address \
-H 'accept: application/json' \
-H 'authorization: Basic YOURAUTHCODEHERE' \
-H 'Content-Type: application/json' \
-H 'CpnyID: YOURCPNYIDHERE' \
-H 'SiteID: YOURSITEIDHERE' \
-H 'cache-control: no-cache' \
-d '{
"CustId": "CUSTID1",
"ShipToId": "ADDR1",
"Notes": "TEST",
"resultCode": 0,
"Addr1": "222 Smith Street",
"Addr2": "#18",
"Attn": "Marvin"
}'

Updating an existing SOAddress record

Now, lets say you want to edit an existing shipto address.  You would do a patch and make sure that you pass the ShipToId that you want in the URL.  It doesn’t have to be in the body.  In the below example, I am updating the ShipToId of ADDR1 for Customer ID CUSTID1 and only updating the field “Attn” to read “Marvin the Martian.”  PATCH will not update any other fields if they aren’t passed.

Curl -X PATCH \
http://yourserver/ctDynamicsSL/api/financial/accountsReceivable/customer/CUSTID1/address/ADDR1 \
-h 'accept: application/json' \
-h 'authorization: Basic YOURAUTHCODEHERE' \
-H 'Content-Type: application/json' \
-H 'CpnyID: YOURCPNYIDHERE' \
-H 'SiteID: YOURSITEIDHERE' \
-H 'cache-control: no-cache' \
-d '{
"CustId": "CUSTID1",
"Attn": "Marvin the Martian"
}'
New Location, New Garden
Using ctAPI to Create Sales Orders