Skip to main content

Creating Clients & Cases

A case and a client are more or less the same thing. The case represents the relationship to your client. In terms of creating a new case/client, the case works as a kind of 'container' for the client. Therefore, when creating a single client, you have to create the case itself and then add the client to the case. When adding a person client, you can use the AddPersonClientToCase mutation and for company clients use AddCompanyClientToCase.

GraphQL mutations for createCase, addPersonClientToCase and addCompanyClientToCase

createCase is for creating the empty case:

mutation createCase($notificationUserId: ID) {
createCase(notificationUserId: $notificationUserId) {
id
name
timeCreated
timeLastEdited
}
}

The following two mutations are for adding a client to an empty case:

mutation addPersonClientToCase($id: ID!, $info: PersonInfo!) {
addPersonClientToCase(id: $id, info: $info) {
id
name
timeCreated
timeLastEdited
}
}

mutation addCompanyClientToCase($id: ID!, $info: CompanyInfo!) {
addCompanyClientToCase(id: $id, info: $info) {
id
name
timeCreated
timeLastEdited
}
}

Mandatory and non-mandatory fields

It is possible to create a client with almost no information if done manually, however, it is highly recommended that you add a name to the client as it will be hard to add later.

Creating an empty case with createCase mutation

When creating a new client you have to first create the case and then later add the client to the created case. The following code creates a case.

public async createCase(notificationUserId?: string | undefined): Promise<CreateCaseMutation> {
return this.gqlClient.mutate({
mutation: CreateCase,
variables: {
notificationUserId,
},
})
.then((createCaseResult) => {
console.log('Created case with id: ', [createCaseResult.data.createCase!.id]);
if (notificationUserId) {
console.log('Added notification user: ', [notificationUserId]);
}
return createCaseResult.data;
})
.catch((error) => console.log(error));
}

Adding a company client with addCompanyClientToCaseGenericCustomerNumber mutation

When the case is created, a new client can be added. In this example it is done with just the company identification number, which corresponds to adding a client in the graphical interface.

public async addCompanyClientToCaseGenericCustomerNumber(caseId: string, GenericCustomerNumber: InputMaybe<string>): Promise<FetchResult<AddCompanyClientToCaseMutation> | void> {
return this.gqlClient.mutate({
mutation: AddCompanyClientToCase,
variables: {
id: caseId,
info: { ExternalId_GenericCustomerNumber: [GenericCustomerNumber] },
} as AddCompanyClientToCaseMutationVariables,
});
}

If you want to create a company client with a generic business registration number, you can follow this example.

public async addCompanyClientToCaseGenericBusinessRegistration(caseId: string, genericBusinessRegistration: string, orgCountryCode: string, name: InputMaybe<string>): Promise<FetchResult<AddCompanyClientToCaseMutation> | void> {
const companyInformation : CompanyInfo = {};

companyInformation.Name = [name];

companyInformation.ExternalId_GenericBusinessRegistrationNumber = [{
countryCode: orgCountryCode,
registrationNumber: genericBusinessRegistration,
}];

return this.gqlClient.mutate({
mutation: AddCompanyClientToCase,
variables: {
id: caseId,
info: companyInformation,
} as AddCompanyClientToCaseMutationVariables,
});
}

Adding a person client with addPersonClientToCase mutation

When adding a person client to a case you can use the same logic as for the company client. Here is an example of this:

public async addPersonClientToCaseName(caseId: string, personName: InputMaybe<string>): Promise<FetchResult<AddCompanyClientToCaseMutation> | void> {
return this.gqlClient.mutate({
mutation: AddPersonClientToCase,
variables: {
id: caseId,
info: { Name: [personName] },
} as AddPersonClientToCaseMutationVariables,
});
}

Code Example

import PublicApiClient from './services/PublicApiClient';
import 'dotenv/config';

(async () => {
const publicApiClient = new PublicApiClient();

const GenericCustomerNumber = '39772388';

const createdCase = await publicApiClient.createCase();

await publicApiClient.addCompanyClientToCaseGenericCustomerNumber(String(createdCase.createCase?.id), GenericCustomerNumber);
})();

AddCompanyClientToCase takes an ID and a CompanyInfo object.