NodeJS API using JSON getting Payload Missing

I am building integration with our own internal system to created invoices via the API on request.

I am getting the following returned error
{"Errors":{"Error":["Payload is missing."]}}

My request code is as follows

request.post(url, data, (error, res, body) => {
if (error) {
console.error(error);
return;
}
console.log(body);
});

and my data code is as below

var data = {
  "payload": {
    "Header": {
      "MessageType": "Request",
      "SubmissionNumber": timestamp,
      "Authentication": {
        "AccNumber": accountNumber,
        "MD5Value": preHash,
        "ApplicationID": app_id
      }
    },
    "Body": {
      "InvoiceData": {
        "InvoiceType": "INVOICE",
        "ClientID": "1343151",
        "ClientAddress": {
          "Address": "123 Test Street<br/>Manchester<br/>MA1 5TH<br/>United Kingdom",
          "CountryISO": "GB"
        },
        "Currency": "GBP",
        "TermDays": "14",
        "Language": "en",
        "InvoiceLines": {
          "ItemLines": {
            "ItemLine": [
              {
                "ItemID": "0",
                "ItemName": "BC1",
                "ItemDescription": "300 Business Cards (250gsm)",
                "ItemNominalCode": "4000",
                "Tax1": {
                  "TaxName": "VAT",
                  "TaxPercentage": "20.00",
                  "TaxAmount": "20"
                },
                "UnitCost": "100",
                "Qty": "1"
              },
              {
                "ItemID": "0",
                "ItemName": "EMB1",
                "ItemDescription": "Embossing Stamp",
                "ItemNominalCode": "4000",
                "Tax1": {
                  "TaxName": "VAT",
                  "TaxPercentage": "20.00",
                  "TaxAmount": "10"
                },
                "UnitCost": "50",
                "Qty": "1"
              }
            ]
          }
        },
        "Scheduling": {
          "SingleInvoiceData": {
            "IssueDate": "2017-05-23"
          }
        }
      }
    }
  }
}

I have generated a submission number and converted the MD5 value etc for the authentication. I am guessing there is something wrong with my formatting, Please can someone help. Tanks

Hi @stuhodgson

From the outset, I can’t see anything wrong with it - the JSON validates correctly so that shouldn’t be the issue.

Is data definitely set before attempting to post the data? Can you output data to the console prior to sending it?


Edit
Just realised the title of your post says XML, but your post provides JSON. They use 2 different endpoints. Can I just double-check which one you’re using please, and what endpoint?

Thanks for your quick reply.

Sorry my topic title mentions XML but it is a JSON request.

Yes I have logged to the console before the request and everything is being set. I have copied some of the output below (Not copied the whole lot in, but it is exactly as my input).

Am I correct in doing a POST request?

If I sent you the App ID, would you be able to see the requests coming in at your end ?

{ payload:
 { Header:
  { MessageType: 'Request',
    SubmissionNumber: '1598449992',
    Authentication:
     { AccNumber: 'XXX',
       MD5Value: 'XXX',
       ApplicationID: 'XXX' } },
 Body:
  { InvoiceData:
     { InvoiceType: 'INVOICE',

We don’t store every request, but what may be worth trying is sending it to a different URL to see what’s coming through.

https://webhook.site may do the trick. If you send the API request through to this link rather than the QuickFile API endpoint, and see what’s coming through.

Thanks Matthew, I have sorted the issue. For reference I wasn’t labelling the data correctly. I needed to reference it like this “{url: url, json: data}” and I have copied the full request below. The emphasis being on referencing the data with the “json” tag. Thanks again

request.post({url: url, json: data}, (error, res, body) => {
  if (error) {
    console.error(error);
    return;
  }
  console.log(body);
 });
1 Like