View on GitHub

documentation

Documentation for DdD products

The following code is used to set up a HttpClient, for REST access. This client can be re-used to all REST routes and token types.

private static HttpClient GetPublicApiClient(string api, string tokenType, string token)
{
    var webApiClient = new HttpClient { BaseAddress = new Uri(api) };
    webApiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, token);
    webApiClient.DefaultRequestHeaders.Accept.Clear();
    webApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    return webApiClient;
}

The GetPublicApiClient method is used in the following examples(s).

This example uses this Swagger/standard endpoint.

It will call the REST API, and get all pages af articles for the given token context (GroupId based).

private static IEnumerable<ArticleDTO> DdD_Rest_GetPaged()
{
    using (var rest = GetPublicApiClient("http://publicapi.dddretail.com", "ddd_token", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"))
    {
        var page = 1;
        var stillPages = true;
        var result = new List<ArticleDTO>();
        while (stillPages)
        {
            var resultJson = rest.GetAsync($"/api/article/page/{page}/pagesize/1000").Result;
            var bodyJson = resultJson.Content.ReadAsStringAsync().Result;
            var pagedModel = JsonConvert.DeserializeObject<PagedDTO<ArticleDTO>>(bodyJson);
            result.AddRange(pagedModel.Results);
 
            if (pagedModel.PageNumber == pagedModel.TotalNumberOfPages)
                stillPages = false;
            page++;
        }
        return result;
    }
}

The following is for SOAP item creation and maintenance.

Supplier and ItemGroup must be created in advance (via REST). DeliveryNoteId has a maximum of 10 characters. You can look up the used article parameters here.

Please note that Qty are set to 0. This will enable creation/update only and no stock changes are made.

This can also be used for item maintenance (i.e. price change).

var articleLine = new ArticleLine
{
    Supplier = 33,
    ItemGroup = 77,
    CostpriceEach = 50.5m,
    SalesPriceEach = 75.75m,
    Kparam1 = "test",
    Kparam2 = "test",
    Kparam3 = "test",
    Kparam4 = "test",
    Kparam5 = "test",
    Vparam1 = "test",
    Vparam2 = "test",
    Vparam3 = "test",
    Vparam4 = "test",
    Vparam5 = "test",
    Ean = xxxxxxxxxxxxxxx,
    Qty = 0
};
var deliveryNote = new DeliveryNote
{
    ClientId = 996001,
    Recipient = 996001,
    Date = DateTime.Now,
    DeliveryDate = DateTime.Now.AddDays(7),
    DeliveryNoteId = "20180301-1",
    MatchOnEan = true,
    IncludeZeroLinesInDraft = false,
    Lines = new List<ArticleLine>() { articleLine }.ToArray()
};
var result = service.MakeDeliveryNote(deliveryNote, 996001, Psk);