API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

400 Bad Request when posting draft invoice via API

+1
Hi

 

I am using this JSON payload to send with REST API to invoices-experimental/drafts:

 

{"date":"2015-06-05","currency":"DKK","paymentTerms":{"paymentTermsNumber":1},"customer":{"customerNumber":1006},"recipient":{"name":"Ole Thorup","address":"Enebaervej 60","zip":"8600","city":"Silkeborg","vatZone":{"vatZoneNumber":1}},"layout":{"layoutNumber":19},"lines":[{"lineNumber":1,"sortKey":1,"unit":{"unitNumber":1},"product":{"productNumber":"1"},"quantity":1.0}]}

 

It works fine when posting from the Chrome extension Advanced Rest Client App but when sending it from my application, I get:

 

{"message":"Validation failed. 1 error(s) found.","errorCode":"E04300","developerHint":"Inspect validation errors and correct your request.","logId":"ee1caf45-8c0b-4174-8219-f0d764479d98","httpStatusCode":400,"errors":{"customer":{"errors":[{"errorMessage":"Property customer is null.","errorCode":"E04042","developerHint":"Property customer must not be null."}]}}

Please advice.
created Jun 5, 2015 by OleWogW
0% Accept Rate
Q 1 A 0 C 0
I am having the same problem, and I am not using C# to generate the request.
I am using fiddler, and here is what I am doing :
1. Set http request type as POST
2. Set url https://restapi.e-conomic.com/invoices/drafts
3. Set the Headers with X-AppSecretToken & X-AgreementGrantToken
4. Set the Json like this :

{
    "date": "2016-01-18",
    "currency": "SEK",
    "exchangeRate": 99,
    "dueDate": "2016-01-25",
    "grossAmount": 100.50,
    "marginInBaseCurrency": 50,
    "marginPercentage": 33,
    "netAmount": 150,
    "roundingAmount": 0.01,
    "vatAmount": 10,
    "layout": {
        "layoutNumber": 1,
        "self": ""
    },
    "project": {
        "projectNumber": 1,
        "self": ""
    },
    "paymentTerms": {
        "paymentTermsNumber": 10,
        "daysOfCredit": 15,
        "self": ""
    },
    "customer": {
        "customerNumber": 144,
        "self": "https://restapi.e-conomic.com/customers/144"
    },
    "recipient": {
        "name": "Atif",
        "address": "something",
        "zip": "41126",
        "city": "Gothenburg",
        "country": "Sweden",
        "ean": "",
        "publicEntryNumber": "",
        "attention": {
            "customerContactNumber": 1,
            "self": ""
        },
        "vatZone": {
            "vatZoneNumber": 1,
            "self": ""
        }
    },
    "deliveryLocation": {
        "deliveryLocationNumber": 1,
        "self": ""
    },
    "delivery": {
        "address": "",
        "zip": "",
        "city": "",
        "country": "",
        "deliveryTerms": "",
        "deliveryDate": "2016-01-20"
    },
    "notes": {
        "heading": "heading",
        "textLine1": "textLine1",
        "textLine2": "textLine2"
    },
    "references": {
        "customerContact": {
            "customerContactnumber": 1,
            "self": ""
        },
        "salesPerson": {
            "employeeNumber": 1,
            "self": ""
        },
        "vendorReference": {
            "employeeNumber": 1,
            "self": ""
        },
        "other": "other"
    },
    "pdf": {
        "self": ""
    },
    "lines": [{
        "lineNumber": 1,
        "sortKey": 1,
        "description": "A description of the product or service sold.",
        "accrual": {
            "startDate": "2016-01-11",
            "endDate": "2016-01-18"
        },
        "unit": {
            "unitNumber": 1,
            "self": ""
        },
        "product": {
            "productNumber": "1",
            "self": ""
        },
        "quantity": 2,
        "unitNetPrice": 500,
        "discountPercentage": 0,
        "unitCostPrice": 400,
        "marginInBaseCurrency": 100,
        "marginPercentage": 20
    }]
}


In response i am getting this :
{"message":"Validation failed. 1 error(s) found.","errorCode":"E04300","developerHint":"Inspect validation errors and correct your request.","logId":"xxxxxxx","httpStatusCode":400,"errors":{"customer":{"errors":[{"errorMessage":"Property customer is null.","errorCode":"E04042","developerHint":"Property customer must not be null."}]}},"logTime":"2017-01-18T11:40:50","errorCount":1}

1 Answer

0
This has been answered in the support.

Short answer is that the .net C# WebClient removes all standard headers between requests
answered Jun 22, 2015 by olej
Visma e-conomic A/S
...