My Products
Help
Anonymous
Not applicable

Using POST to create Customer, Article etc

by Anonymous

I have no problem using GET functions in the API but I cant find any documentation for the POST (or PUT) method. On:

https://eaccountingapi-sandbox.test.vismaonline.com/swagger/ui/index
you can read about different operations - but only the entire definition of the array. It seems strage that I should fill all the datafields, and I don't think i should create the "id"(which seems like some kind of key but that I can't find any documentation for).


Jag har inga problem att använda GET metoder i API:et, men jag hittar inget i dokumentationen om POST (och PUT) metoder. På:
https://eaccountingapi-sandbox.test.vismaonline.com/swagger/ui/index
kan man läsa om olika operationer - men hela array-definitionen är med. Jag kan väl rimligen inte fylla alla fält, och "id" (som verkar vara en nyckel men som jag inte hittar någon dokumentation om) tror jag inte jag skall definiera.

10 REPLIES 10
Anonymous
Not applicable

by Anonymous

Hi,

I assume that you want to have a POST or PUT JSON that only contains the necessary fields, not every single property.

If that is what you meant, I recommend that you create it in the UI, and make a GET request.

 

When you have the response from the GET request you can use that JSON as a basis for the POST/PUT. Then remove the properties one by one according to what you need.

 

PS: this is how I would do it.

Anonymous
Not applicable

by Anonymous (Updated ‎04-10-2019 14:00 ( )

I dont know what UI (user interface?) youre talking about.

If I make a Get call:

GET v2/customers

The result is:

array (
'Meta' =>
array (
'CurrentPage' => 1,
'PageSize' => 50,
'TotalNumberOfPages' => 1,
'TotalNumberOfResults' => 1,
'ServerTimeUtc' => '2019-10-04T11:37:37.638943Z',
),
'Data' =>
array (
0 =>
array (
'Id' => '2391d0c7-4665-41fe-b39b-d18f319c74cb',
'CustomerNumber' => '1',
'CorporateIdentityNumber' => '',
'ContactPersonEmail' => '',
'ContactPersonMobile' => '',
'ContactPersonName' => '',
'ContactPersonPhone' => '',
'CurrencyCode' => 'SEK',
'GLN' => NULL,
'EmailAddress' => 'epost@mail.com',
'InvoiceAddress1' => 'Gatan 1',
'InvoiceAddress2' => '',
'InvoiceCity' => 'SÄFFLE',
'InvoiceCountryCode' => 'SE',
'InvoicePostalCode' => '66100',
'DeliveryCustomerName' => NULL,
'DeliveryAddress1' => NULL,
'DeliveryAddress2' => NULL,
'DeliveryCity' => NULL,
'DeliveryCountryCode' => NULL,
'DeliveryPostalCode' => NULL,
'DeliveryMethodId' => NULL,
'DeliveryTermId' => NULL,
'PayToAccountId' => '7770d279-65d8-4e6b-b10f-675cc558b66a',
'Name' => 'Testgubbe',
'Note' => '',
'ReverseChargeOnConstructionServices' => false,
'WebshopCustomerNumber' => NULL,
'MobilePhone' => '',
'Telephone' => '',
'TermsOfPaymentId' => '8f9a8f7b-5ea9-44c6-9725-9b8a1addb036',
'TermsOfPayment' =>
array (
'Id' => '8f9a8f7b-5ea9-44c6-9725-9b8a1addb036',
'Name' => '30 dagar netto',
'NameEnglish' => 'Net 30 days',
'NumberOfDays' => 30,
'TermsOfPaymentTypeId' => 0,
'TermsOfPaymentTypeText' => NULL,
'AvailableForSales' => false,
'AvailableForPurchase' => false,
),
'VatNumber' => '',
'WwwAddress' => '',
'LastInvoiceDate' => NULL,
'IsPrivatePerson' => true,
'DiscountPercentage' => 0,
'ChangedUtc' => '2019-10-03T12:02:59.8267883Z',
'IsActive' => true,
'ForceBookkeepVat' => false,
'EdiGlnNumber' => '',
'SalesDocumentLanguage' => 'sv',
'ElectronicAddress' => NULL,
'ElectronicReference' => NULL,
'EdiServiceDelivererId' => NULL,
'AutoInvoiceActivationEmailSentDate' => NULL,
'AutoInvoiceRegistrationRequestSentDate' => NULL,
'EmailAddresses' =>
array (
),
'CustomerLabels' => NULL,
'IsFutureInvoiceDateAllowed' => true,
),
),
)

But if I make a POST:
POST v2/customers

{"CustomerNumber":"1423","Name":"Testkund","Telephone":"011-23443","InvoiceAddress1":"Gatan 1","InvoiceAddress2":"","InvoiceCity":"FLEN","InvoicePostalCode":"23443","InvoiceCountryCode":"SE","DeliveryAddress1":"Gatan 1","DeliveryAddress2":"","DeliveryCity":"FLEN","DeliveryPostalCode":"23443","DeliveryCountryCode":"SE","IsActive":true,"IsPrivatePerson":true}

I get error 2000: DataModelValidationError


Anonymous
Not applicable

by Anonymous

The full reply you should have gotten should have looked like this:

{
    "ErrorCode": 2000,
    "DeveloperErrorMessage": "ValidateModelAttributeException - Required property 'TermsOfPaymentId' not found in JSON. Path '', line 1, position 359. TermsOfPaymentId is a required field. ",
    "ErrorId": "c1d023b1-6ee9-4961-87c2-b1406c1b5c18"
}

As you can see from the error message there are some necessary properties missing:

"TermsOfPaymentId": "<insert the id here>"

 

Anonymous
Not applicable

by Anonymous (Updated ‎04-10-2019 14:12 ( )

I have figured that out. But whats the id? Can i just invent one or? 1?
In my example I got 8f9a8f7b-5ea9-44c6-9725-9b8a1addb036
Then after that I se

array (
'Id' => '8f9a8f7b-5ea9-44c6-9725-9b8a1addb036',
'Name' => '30 dagar netto',
'NameEnglish' => 'Net 30 days',
'NumberOfDays' => 30,
'TermsOfPaymentTypeId' => 0,
'TermsOfPaymentTypeText' => NULL,
'AvailableForSales' => false,
'AvailableForPurchase' => false,
)


Will that be mandatory to later or can I just use 8f9a8f7b-5ea9-44c6-9725-9b8a1addb036 - or is the Id something I request?

Anonymous
Not applicable

by Anonymous (Updated ‎04-10-2019 14:17 ( )

You cannot set or choose an ID, it is a GUID that is set in the system to identify that specific item.

You can have it on the JSON, but it will not do anything.
It will always be set by the backend.

 

The Terms of payment ID or another property in the eAccounting system is predefined and you can find it by making GET calls to their respective endpoints or an endpoint that contains those properties.

Anonymous
Not applicable

by Anonymous

Its mandatory but i cant set it? Thats quite strange. Does that means that i can use any value?

Anonymous
Not applicable

by Anonymous

It is a read-only property:

post customers.PNG

Accepted solution
Anonymous
Not applicable

by Anonymous

Oh thanks,

that "Model" link was not visable - there were the definitions I was looking for.

Anonymous
Not applicable

by Anonymous

You know what,

if found a method namend termsofpayments,

there i get the ids of the terms.

I think that´s what should be used.

Anonymous
Not applicable

by Anonymous

Ok, I used 8f9a8f7b-5ea9-44c6-9725-9b8a1addb036 and it worked.
I don´t know what Im doing - but I guest that 8f9a8f7b-5ea9-44c6-9725-9b8a1addb036 is just a constant?