Error: Recorderror purchase_ledger_account is invalid

Hey Guys,

I want to add a customer via the API like I did several times before in the past - but it doesn't work anymore although I haven't changes anything in my requests an payloads.

The Error is:

`422 - [{"$severity":"error","$dataCode":"RecordInvalid","$message":"is invalid","$source":"purchase_ledger_account"}]`

The URL is: `POST api.accounting.sage.com/.../contacts`

The payload is:

```

{
  contact: {
    name: 'string',
    reference: 'string',
    tax_number: 'string',
    aux_reference_vendor: 'string',
    aux_reference_customer: 'string',
    default_purchase_ledger_account_id: '126871e4861c11e9bcfe0268dc652fba',
    default_sales_tax_rate_id: 'DE_ZERO',
    email: 'string',
    main_address: [Object],
    main_contact_person: [Object],
    bank_account_details: [Object],
    tax_treatment: [Object],
    contact_type_ids: [Array],
    aux_reference: 'string',
  }
}

```

I don't even have a purchase_ledger_account attribute in the payload - and if the error means that the `default_purchase_ledger_account_id` invalid, here is the response to the call to  `api.accounting.sage.com/.../126871e4861c11e9bcfe0268dc652fba`

```

{
"id": "126871e4861c11e9bcfe0268dc652fba",
"displayed_as": "Sonstige Leistungen eines im anderen EU-Land ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer (3123)",
"$path": "/ledger_accounts/126871e4861c11e9bcfe0268dc652fba",
"created_at": "2019-06-03T16:24:33Z",
"updated_at": "2019-06-03T16:24:33Z",
"ledger_account_group": {
"id": "EXPENSE",
"displayed_as": "Ausgabe"
},
"name": "Sonstige Leistungen eines im anderen EU-Land ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer",
"display_name": "Sonstige Leistungen eines im anderen EU-Land ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer",
"visible_scopes": [
"journals",
"purchasing_eu",
"reporting"
],
"included_in_chart": true,
"nominal_code": 3123,
"ledger_account_type": {
"id": "DIRECT_EXPENSES",
"displayed_as": "Einzelkosten",
"$path": "/ledger_account_types/DIRECT_EXPENSES"
},
"ledger_account_classification": {
"id": "DE_RECEIVING_INVENTORY",
"displayed_as": "3 - Wareneingangs- und Bestandskonten",
"$path": "/ledger_account_classifications/DE_RECEIVING_INVENTORY"
},
"tax_rate": {
"id": "DE_STANDARD",
"displayed_as": "19,00% USt",
"$path": "/tax_rates/DE_STANDARD"
},
"fixed_tax_rate": true,
"visible_in_banking": false,
"visible_in_expenses": false,
"visible_in_journals": true,
"visible_in_other_payments": false,
"visible_in_other_receipts": false,
"visible_in_reporting": true,
"visible_in_sales": false,
"is_control_account": false,
"control_name": null,
"display_formatted": "3123 - Sonstige Leistungen eines im anderen EU-Land ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer",
"tax_recoverable": null,
"recoverable_percentage": null,
"non_recoverable_ledger_account": null
}

```

I also tried several other ledger account ids with no succes.

Parents
  • The guys from the chat told me to post all my questions about the API here. I've been waiting 8 days to get an answer, will I get an answer here someday? 

  • Hi ,

    first of all: sorry for not responding earlier, I was on holiday last week.

    Regarding your question:

    Looking at your payload, you are trying to assign a sales_tax_rate and also a default_purchase_ledger_account. What kind of contact are you trying to create (customer or vendor)? 

    If you post a vendor, you need to post default_sales_tax_rate_id as well as default_sales_ledger_account_id, if you post a vendor, it needs to be default_purchase_tax_rate_id and default_purchase_ledger_account_id. 

    I know that the error messages are not really helpful, but could you try to adjust the payload as I described and see if the error still occurs?

    Regards, Tim

  • Hi Tim,

    thanks for your reply.

    I have to create a customer aswell as a vendor so therefore I build the body payload object to have all of the above mentioned keys and use it as the payload for the vendor. After that I hit the POST contacts endpoint again with a copy of the payload with modified reference, contact_type_ids and aux_reference.

    I will now try to send only the keys needed in the payloads.

  • Hey Tim,

    here is the whole error:

    {
      "name": "StatusCodeError",
      "statusCode": 422,
      "message": "422 - [{\"$severity\":\"error\",\"$dataCode\":\"RecordInvalid\",\"$message\":\"is invalid\",\"$source\":\"purchase_ledger_account\"}]",
      "error": [{ "$severity": "error", "$dataCode": "RecordInvalid", "$message": "is invalid", "$source": "purchase_ledger_account" }],
      "options": {
        "url": "https://api.accounting.sage.com/v3.1/contacts",
        "headers": {
          "Host": "api.accounting.sage.com",
          "Authorization": "Bearer XXX",
          "Content-Type": "application/json",
          "Accept": "application/json"
        },
        "body": {
          "contact": {
            "name": "name",
            "reference": "reference",
            "tax_number": "tax_number",
            "aux_reference_vendor": "aux_reference_vendor",
            "aux_reference_customer": "aux_reference_customer",
            "email": "email",
            "main_address": {
              "name": "name",
              "address_line_1": "address_line_1",
              "city": "city",
              "postal_code": "postal_code",
              "country_group_id": "country_group_id",
              "country_id": "country_id",
              "is_main_address": true
            },
            "main_contact_person": {
              "name": "name",
              "mobile": "mobile",
              "email": "email",
              "contact_person_type_ids": ["ACCOUNTS"],
              "job_title": "job_title",
              "is_main_contact": true,
              "is_preferred_contact": true
            },
            "bank_account_details": { "account_name": "account_name", "bic": "bic", "iban": "iban" },
            "tax_treatment": { "home_tax": false, "eu_tax_registered": true, "eu_not_tax_registered": false, "rest_of_world_tax": false },
            "contact_type_ids": ["VENDOR"],
            "default_purchase_ledger_account_id": "1268d957861c11e9bcfe0268dc652fba",
            "default_purchase_tax_rate_id": "DE_NO_TAX",
            "aux_reference": "aux_reference"
          }
        },
        "json": true,
        "method": "POST",
        "simple": true,
        "resolveWithFullResponse": false,
        "transform2xxOnly": false
      },
      "response": {
        "statusCode": 422,
        "body": [{ "$severity": "error", "$dataCode": "RecordInvalid", "$message": "is invalid", "$source": "purchase_ledger_account" }],
        "headers": {
          "content-type": "application/json",
          "content-length": "111",
          "connection": "close",
          "date": "Tue, 05 Nov 2019 09:23:46 GMT",
          "x-amzn-requestid": "77304bca-0435-4f38-9602-d2cba2a6c164",
          "x-runtime": "0.174067",
          "x-amzn-remapped-content-length": "111",
          "x-amzn-remapped-connection": "close",
          "x-request-id": "9a6a83f6-8c3e-4e0c-9f0b-2d9dafdc97cb",
          "x-correlation-context": "{}",
          "x-amz-apigw-id": "CrbhUEXbDoEF3Iw=",
          "status": "422 Unprocessable Entity",
          "cache-control": "no-cache",
          "x-amzn-trace-id": "Root=1-5dc13fa1-986a4777dae5aeca41af41d4;Sampled=0",
          "x-amzn-remapped-date": "Tue, 05 Nov 2019 09:23:46 GMT",
          "x-cache": "Error from cloudfront",
          "via": "1.1 8d84df16ba20ff1d2ca3914948494e04.cloudfront.net (CloudFront)",
          "x-amz-cf-pop": "FRA54",
          "x-amz-cf-id": "nDqn02Zd5kycyJkLz67m_QWYUYJ4UMA1TtmJozjwkV1P5fRKBa08Kw=="
        },
        "request": {
          "uri": {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "api.accounting.sage.com",
            "port": 443,
            "hostname": "api.accounting.sage.com",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/v3.1/contacts",
            "path": "/v3.1/contacts",
            "href": "https://api.accounting.sage.com/v3.1/contacts"
          },
          "method": "POST",
          "headers": {
            "Host": "api.accounting.sage.com",
            "Authorization": "Bearer XXX",
            "Content-Type": "application/json",
            "Accept": "application/json",
            "content-length": 997
          }
        }
      }
    }
    

    I tried several different things but wasn't able to get it to work. Could you help me please?

    Also the problem exists only on this particular request. I am able to create other customers and vendors.

Reply
  • Hey Tim,

    here is the whole error:

    {
      "name": "StatusCodeError",
      "statusCode": 422,
      "message": "422 - [{\"$severity\":\"error\",\"$dataCode\":\"RecordInvalid\",\"$message\":\"is invalid\",\"$source\":\"purchase_ledger_account\"}]",
      "error": [{ "$severity": "error", "$dataCode": "RecordInvalid", "$message": "is invalid", "$source": "purchase_ledger_account" }],
      "options": {
        "url": "https://api.accounting.sage.com/v3.1/contacts",
        "headers": {
          "Host": "api.accounting.sage.com",
          "Authorization": "Bearer XXX",
          "Content-Type": "application/json",
          "Accept": "application/json"
        },
        "body": {
          "contact": {
            "name": "name",
            "reference": "reference",
            "tax_number": "tax_number",
            "aux_reference_vendor": "aux_reference_vendor",
            "aux_reference_customer": "aux_reference_customer",
            "email": "email",
            "main_address": {
              "name": "name",
              "address_line_1": "address_line_1",
              "city": "city",
              "postal_code": "postal_code",
              "country_group_id": "country_group_id",
              "country_id": "country_id",
              "is_main_address": true
            },
            "main_contact_person": {
              "name": "name",
              "mobile": "mobile",
              "email": "email",
              "contact_person_type_ids": ["ACCOUNTS"],
              "job_title": "job_title",
              "is_main_contact": true,
              "is_preferred_contact": true
            },
            "bank_account_details": { "account_name": "account_name", "bic": "bic", "iban": "iban" },
            "tax_treatment": { "home_tax": false, "eu_tax_registered": true, "eu_not_tax_registered": false, "rest_of_world_tax": false },
            "contact_type_ids": ["VENDOR"],
            "default_purchase_ledger_account_id": "1268d957861c11e9bcfe0268dc652fba",
            "default_purchase_tax_rate_id": "DE_NO_TAX",
            "aux_reference": "aux_reference"
          }
        },
        "json": true,
        "method": "POST",
        "simple": true,
        "resolveWithFullResponse": false,
        "transform2xxOnly": false
      },
      "response": {
        "statusCode": 422,
        "body": [{ "$severity": "error", "$dataCode": "RecordInvalid", "$message": "is invalid", "$source": "purchase_ledger_account" }],
        "headers": {
          "content-type": "application/json",
          "content-length": "111",
          "connection": "close",
          "date": "Tue, 05 Nov 2019 09:23:46 GMT",
          "x-amzn-requestid": "77304bca-0435-4f38-9602-d2cba2a6c164",
          "x-runtime": "0.174067",
          "x-amzn-remapped-content-length": "111",
          "x-amzn-remapped-connection": "close",
          "x-request-id": "9a6a83f6-8c3e-4e0c-9f0b-2d9dafdc97cb",
          "x-correlation-context": "{}",
          "x-amz-apigw-id": "CrbhUEXbDoEF3Iw=",
          "status": "422 Unprocessable Entity",
          "cache-control": "no-cache",
          "x-amzn-trace-id": "Root=1-5dc13fa1-986a4777dae5aeca41af41d4;Sampled=0",
          "x-amzn-remapped-date": "Tue, 05 Nov 2019 09:23:46 GMT",
          "x-cache": "Error from cloudfront",
          "via": "1.1 8d84df16ba20ff1d2ca3914948494e04.cloudfront.net (CloudFront)",
          "x-amz-cf-pop": "FRA54",
          "x-amz-cf-id": "nDqn02Zd5kycyJkLz67m_QWYUYJ4UMA1TtmJozjwkV1P5fRKBa08Kw=="
        },
        "request": {
          "uri": {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "api.accounting.sage.com",
            "port": 443,
            "hostname": "api.accounting.sage.com",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/v3.1/contacts",
            "path": "/v3.1/contacts",
            "href": "https://api.accounting.sage.com/v3.1/contacts"
          },
          "method": "POST",
          "headers": {
            "Host": "api.accounting.sage.com",
            "Authorization": "Bearer XXX",
            "Content-Type": "application/json",
            "Accept": "application/json",
            "content-length": 997
          }
        }
      }
    }
    

    I tried several different things but wasn't able to get it to work. Could you help me please?

    Also the problem exists only on this particular request. I am able to create other customers and vendors.

Children