ContaMakeCustomer
Back to ListDescription: Create a customer in Conta
FileMaker Prototype:
Set Variable [$res; ACF_Run("ContaMakeCustomer"; string_PrimaryKey)]
Category: CONTA API
Dependencies
- getContaBaseURL: Get the CONTA API base URL, Sandbox or production URLs
- ValidateAndCleanPhoneNumber: Clean phone numbers, ensure it is 8 digits.
- getContaApiKeyandNumber: Retrieve the Conta credentials used in the API
- ContaVerifyAPIresponce: Look for error message in Conta API responce
NOTE: This function serves as a reference template. To use it effectively, you may need to adjust certain parts of the code, such as field names, database structures, and specific data lists to fit the requirements of your system. This customization allows the function to work seamlessly within your environment.
ContaMakeCustomer Function Overview
The ContaMakeCustomer function is part of the Conta Integration Suite of ACF functions for FileMaker, designed to streamline customer creation in the Conta accounting system using its API.
This function gathers data from the Customer and Contacts tables, formats it into a JSON object according to Conta’s API specifications, and then sends the data to the API endpoint. The function processes the API response, checking for any errors, and if successful, updates the Customer table with the new Conta Customer ID, ensuring it is readily available for future API interactions.
If successful, the function returns "OK".
Important: Before calling this function, perform a Commit Record/Request to ensure:
- SQL has access to the latest updates.
- The Customer record is not locked, which would prevent the function from updating it.
Example Usage
Set Variable [$res; ACF_Run("ContaMakeCustomer"; Customers::PrimaryKey)]
If [$res = "OK"]
// Everything is OK
Else
// Handle errors: alert customer, show custom dialog, etc.
End IfFunction source:
Function ContaMakeCustomer(string PrimaryKey)
array int cuKundeID;
array string cuKundeNavn, cuAdresse1, cuAdresse2, cuPostNr, cuSted, cuCountry;
array string cuLCountry, cuLAdresse1, cuLAdresse2, cuLPostNr, cuLSted, cuMobil, cuEpost;
array string cuKundetype, cuOrgNr;
array string coFirstName, coLastName, coName, coMobile, coEmail;
array int coID;
string sql = "SELECT KundeID, KundeNavn, Adresse1, Adresse2, PostNr, Sted,
Country, LAdresse1, LAdresse2, LPostNr, LSted, LCountry, Mobil, Epost,
Kundetype, OrgNr
FROM Kunder
WHERE PrimaryKey = :PrimaryKey
INTO :cuKundeID, :cuKundeNavn, :cuAdresse1, :cuAdresse2, :cuPostNr, :cuSted, :cuCountry, :cuLAdresse1, :cuLAdresse2, :cuLPostNr, :cuLSted, :cuLCountry, :cuMobil, :cuEpost, :cuKundetype, :cuOrgNr
";
string res = ExecuteSQL ( sql );
if ( res != "OK") then
alert (res);
end if
if ( sizeof ( cuKundeNavn) != 1) then
throw "Customer not found";
end if
string kundetype = (( lower(cuKundetype[1]) == "priv")?"INDIVIDUAL":"ORGANIZATION");
string phone;
JSON cust;
phone = ValidateAndCleanPhoneNumber (cuMobil[1]);
// Build the JSON object.
cust = JSON(
"customerAddressCity", cuSted[1],
"customerAddressCountry", cuCountry[1],
"customerAddressLine1", cuAdresse1[1],
"customerAddressLine2", cuAdresse2[1],
"customerAddressPostcode", cuPostNr[1],
"customerType", kundetype,
"dateOfBirth", "",
"daysUntilEstimateOverdue", 14,
"daysUntilPaymentReminder", 30,
"defaultInvoiceDiscount", "0",
"deliveryAddressCity", cuLSted[1],
"deliveryAddressCountry", cuLCountry[1],
"deliveryAddressLine1", cuLAdresse1[1],
"deliveryAddressLine2", cuLAdresse2[1],
"deliveryAddressPostcode", cuLPostNr[1],
"efakturaEmailAddress", cuEpost[1],
"efakturaName", cuKundeNavn[1],
"efakturaPhoneNo", phone,
"emailAddress", cuEpost[1],
"invoiceDeliveryMethod", "EMAIL",
"isActive", true,
"mailingAddressCity", cuSted[1],
"mailingAddressCountry", cuCountry[1],
"mailingAddressLine1", cuAdresse1[1],
"mailingAddressLine2", cuAdresse2[1],
"mailingAddressPostcode", cuPostNr[1],
"name", cuKundeNavn[1],
"orgNo", cuOrgNr[1],
"parentCompanyNameForNuf", "",
"phoneNo", phone,
"vismaNo", ""
);
// Extra..."ehfRecipientOrgNo", cuOrgNr[1],"id", cuKundeID[1],
// Get the Contaxts from the Contacts table.
sql = "SELECT FirstName, LastName, Name, Mobile, Email, id
FROM Contacts
WHERE CustomerFK = :PrimaryKey AND InvoiceRecipient = 'Yes'
INTO :coFirstName, :coLastName, :coName, :coMobile, :coEmail, :coID";
res = ExecuteSQL ( sql );
if ( res != "OK") then
alert (res);
return res;
end if
int i, j;
j= sizeof (coFirstName );
print "Contacts="+j;
for (i=1, j)
phone = ValidateAndCleanPhoneNumber (coMobile[i]);
if ( phone != "") then
cust["contacts[]"] = JSON(
"id", coID[i],
"customerId", cuKundeID[1],
"name", coName[i],
"phoneNo", phone,
"emailAddress", coEmail[i],
"title", ""
);
else
cust["contacts[]"] = JSON(
"id", coID[i],
"customerId", cuKundeID[1],
"name", coName[i],
"emailAddress", coEmail[i],
"title", ""
);
end if
end for
// Do the API call
JSON apidata = getContaApiKeyandNumber();
print string(apidata);
if ( apidata["APIkey"] == "") then
alert ("No API key found");
return "ERROR: Missing APIkey";
end if
string APIkey = apidata["APIkey"];
bool production = (apidata["Production"]=="1");
int compOrg = int(apidata["CompNo"]);
string hdr = 'apiKey:'+APIkey;
string url = getContaBaseURL(production)+"/invoice/organizations/"+compOrg+"/customers";
print "\n"+url;
string data = string(cust);
res = HTTP_POST ( url, data, hdr);
print res;
string contaCustID;
// Verify the result-
JSON apiRes = res;
if (ContaVerifyAPIresponce(apiRes)) then
contaCustID = apires["id"];
$$CustContaID = contaCustID;
print "ContaCustID = " + contaCustID;
// Update ContaCustomerID on the customer.
sql = "UPDATE Kunder SET ContaCustomerID = :contaCustID, ContaResponce = :res
WHERE PrimaryKey = :PrimaryKey";
res = ExecuteSQL( sql );
if ( res != "") then
alert ( res );
return "ERROR Update ContaCustID..."+res;
end if
end if
return "OK";
End
Customization
To integrate ContaMakeCustomer with your solution, customize it by:
- Modifying SQL statements to match your database’s specific table and field names.
Screenshots of Table Structure
Customers Table (Kunder in Norwegian)

Contacts Table

Preferences Table

Defenition of the FileMaker tables.
Customers (Kunder in Norwegian)
| Field Name | Type | Description |
|---|---|---|
| PrimaryKey | Text. | Unique UUID for this customer. |
| KundeID | Number | Customer Number. |
| KundeNavn | Text | Name of the customer |
| Adresse1 | Text | Primary address line for the customer |
| Adresse2 | Text | Secondary address line (optional) |
| PostNr | Text | Postal code for the primary address |
| Sted | Text | City or locality for the primary address |
| Country | Text | Country code or name for the primary address |
| LAdresse1 | Text | Delivery address line 1 |
| LAdresse2 | Text | Delivery address line 2 (optional) |
| LPostNr | Text | Postal code for the delivery address |
| LSted | Text | City or locality for the delivery address |
| LCountry | Text | Country code or name for the delivery address |
| Mobil | Text | Mobile phone number of the customer |
| Epost | Text | Email address of the customer |
| Kundetype | Text | Customer type or category |
| OrgNr | Text | Organization or business registration number |
Contacts
| Field Name | Type | Description |
|---|---|---|
| CustomerFK | Text | Relation field to Customers Primary Key |
| FirstName | String | First name of the contact |
| LastName | String | Last name of the contact |
| Name | String | Full name of the contact |
| Mobile | String | Mobile phone number of the contact |
| String | Email address of the contact | |
| InvoiceRecipient | Text | Yes/No field, only contacts with Yes is sent to Conta |
| id | Integer | Unique identifier for the contact |
