ANSWERED

Retail/WebOffice > Creating a Customer through the API

From Russell: I had a question from a client about problems creating a customer through the Retail Shop. Retail and Back Office use the same authenticated call via the Angular v3Post call. In this case, the client struggled to figure out which fields were missing from the call and was running into problems with the Validation hook in Disco. Here's my response to them: On the Customer Create issue, I'm seeing missing elements on the call in, and the ValidateApplicationHook is not managing them well when they're missing. The payload you sent in that failed is missing the following two elements: 1. PrimaryPhone 2. PostalCode must be passed in on the addresses, but as "Zip". (because the Azure Gateway does the mapping from PostalCode to Zip when you have used the public API in the past. You're calling through the Retail pathway now. Here is the swagger page for API2 (retail), focused on the CreateCustomer call: https://api2.directscale.com/swagger/ui/index#!/Customers/Customers_CreateCustomer) (see payload below) **FYI**: On a CreateCustomer call from Retail, it looks like you only need to pass in "PrimaryAddress". The Retail API code creates a Disco "ShippingAddress" and "DefaultAddress" based on the Primary Address. If you want to set a shipping address differently, you'll need to call UpdateCustomer or the like, but I haven't looked into that. This is at least what I'm interpreting as I look through the code. I also recommend you do some different null checking on validation elements in the WriteApplication hook (which is called in Create Customer, too). Something about the way it's done is blowing up if something is missing (this may be an artifact because I had to decompile the code, but I think you need to check for null or missing elements before using the reflection you've set up). But, if you get those two fields added from above, it'll work fine. **Note**: this prompted the actual inclusion of the API payload. This is a little different than the public API because we do some mapping to fields you see here slightly differently. That said, it makes the same Disco call. Payload of /api/Customers/CreateCustomer (I removed the DefaultAddress and ShippingAddress because they're stripped out on their way into Corpadmin) { "BackOfficeId": "string", "BirthDate": "2021-01-18T23:14:02.081Z", "CompanyName": "string", "CustomerStatus": 0, "CustomerType": 0, "EmailAddress": "string", "ExternalReferenceId": "string", "FirstName": "string", "LanguageCode": "string", "LastName": "string", "Password": "string", "PrimaryPhone": "string", "SecondaryPhone": "string", "SendEmails": true, "SignUpDate": "2021-01-18T23:14:02.081Z", "SponsorId": 0, "TaxExemptId": "string", "TaxId": "string", "TermsAccepted": "string", "TextPhone": "string", "Username": "string", "WebAlias": "string", "RomanizedFirstName": "string", "RomanizedLastName": "string", "LegalFirstName": "string", "LegalLastName": "string" "PrimaryAddress": { "ID": 0, "Line1": "string", "Line2": "string", "Line3": "string", "City": "string", "State": "string", "Zip": "string", "CountryCode": "string" } }