API returning errors for all requests

Problem reported by Adrian Bhagat 6 months ago

I am trying to make use of the API from a C# client but I am getting errors returned for all queries.

1) A simple query to listPaymentMethods or listAccountCodes returns null. 2) Listing invoices returns a message that the maximum message size has been exceeded. Increasing the max message size gives a null result. 3) Creating an invoice returns "You are trying to process a transaction prior to the opening accounting date." even though the creation date is set to today.

The C# example code provided in the documentation seems to be out of date.

I have included my code below. Any help you can give would be much appreciated.

class ClearbooksClient { public static string ServiceUrl = "https://secure.clearbooks.co.uk/api/accounting/soap/";; public static EndpointAddress endpoint = new EndpointAddress(ServiceUrl); public static string ApiKey = "redacted";

private static readonly Clearbooks.authenticate auth = new Clearbooks.authenticate
{
    apiKey = ApiKey
};

public ClearbooksClient()
{
}

public async Task AddInvoice()
{
    try
    {
        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
        {
            //MaxReceivedMessageSize = 1048576
        };

        Clearbooks.AccountingPortClient client = new Clearbooks.AccountingPortClient(binding, endpoint);

        Clearbooks.listPaymentMethodsResponse r1 = await client.listPaymentMethodsAsync(auth);
        Clearbooks.PaymentMethod[] res1 = r1.listPaymentMethodsResult;
        //res1 is null

        Clearbooks.InvoiceQuery query2 = new Clearbooks.InvoiceQuery
        {
            ledger = "sales",
            id = new int[] { 1000 }
        };
        Clearbooks.listInvoicesResponse r2 = await client.listInvoicesAsync(auth, query2);
        Clearbooks.Invoice[] res2 = r2.listInvoicesResult;
        //res2 is null

        Clearbooks.InvoiceQuery query3 = new Clearbooks.InvoiceQuery
        {
            ledger = "sales",
            status = "all",
        };
        Clearbooks.listInvoicesResponse r3 = await client.listInvoicesAsync(auth, query3);
        Clearbooks.Invoice[] res3 = r3.listInvoicesResult;
        //Throws exception "The maximum message size quota for incoming messages (65536) has been exceeded.
        //If the MaxReceivedMessageSize is increased on the binding, res3 is null

        Clearbooks.Invoice invoice = new Clearbooks.Invoice
        {
            dateCreated = DateTime.Now,
            dateDue = DateTime.Now,
            description = "Shop items",
            type = "sales",
            entityId = 2, //'shop customers'
            creditTerms = 0,
            status = "approved"
        };
        Clearbooks.Item item = new Clearbooks.Item
        {
            description = "Shop sales",
            unitPrice = 123.00,
            quantity = 1.0,
            //vatRate
            vat = 11.40,
            vatSpecified = true,
            type = 1001001 //'shop items'?
        };
        invoice.items = new Clearbooks.Item[] { item };

        Clearbooks.createInvoiceResponse r4 = await client.createInvoiceAsync(auth, invoice);
        //Throws exception: "You are trying to process a transaction prior to the opening accounting date."
        Clearbooks.InvoiceReturn res4 = r4.createInvoiceResult;

        Clearbooks.listAccountCodesResponse r5 = await client.listAccountCodesAsync(auth);
        Clearbooks.AccountCode[] res5 = r5.listAccountCodesResult;
        //res5 is null

        return true;
    }
    catch (Exception ex)
    {
        Debug.WriteLine( ex.Message);
        return false;
    }
}

}

6 Replies

Hi Adrian,

May I ask what WSDL URL you are using for this?

All the best,

Mohamed.

Hi Adrian,

I am very happy to hear! That's wonderful. Please do let me know if you need anything further.

All the best,

Mohamed.

Reply to this problem

Attach images by dragging and dropping or upload
 

Your comments will be public and can be answered by anyone in the Clear Books community.

Find out what we do and who we are