Jump to content

How to Link invoice and credit note using Sage API


 Share

Recommended Posts

If I already have Invoice on Sage and I want to create a Credit note linked to that Invoice, what invoice data should I send with the credit note data to link them and make invoice Paid.
I am currently sending data like this for creating Credit note in CURL(PHP) -
 

$data = '{
                    "sales_credit_note": {
                        "contact_id": "'.$contact_id.'",
                        "currency_id": "'.$currency_id.'",
                        "exchange_rate": "1",
                        "date": "'.$date.'",
                        "reference": "'.$reference.'",
                        "main_address": {
                            "address_line_1": "'.$billing_street.'",
                            "address_line_2": "'.$billing_state.'",
                            "city": "'.$billing_city.'",
                            "postal_code": "'.$billing_zip.'",
                            "country_id": "GB"
                            },
                            "credit_note_lines": [' '],
                            "net_amount": "'.$net_amount.'",
                            "total_amount": "'.$net_amount.'",
                            "total_quantity": "'.$total_quantity.'"
                        }
                    }';

It only creates the credit note but I also want to link Invoice with it.
Link to comment
Share on other sites

Hello Mark,

I have read the payments section but I am unable to find out how can I allocate credit note with invoice on sage.

Like in this I can pass invoice id in artefact_id, but where should I put credit note id or credit note data which I want to link with that invoice?

POST /contact_payments
Content-Type: application/json
 
{
  "contact_payment": {
    "transaction_type_id": "CUSTOMER_RECEIPT",
    "payment_method_id": "CREDIT_DEBIT",
    "contact_id": "7dfc261d51eb9c107bff7273862f6e80",
    "bank_account_id": "27cf77a0e56b4c420345893cfc404c94",
    "date": "2018-04-06",
    "total_amount": "99.99",
    "allocated_artefacts": [
      {
        "artefact_id": "ba0473ae7201b61bc1d820059ff69551",
        "amount": "77.77"
      }
    ]
  }
}
Link to comment
Share on other sites

The example we have in the guide(attached) uses the contact_allocations API. You are creating an allocation and do not require the contact_payment API.

The example refers to the credit value of a payment on account but this could be any credit value(including a credit note) on the customer account. 

You need to pass in the amount being allocated as well as the sales_invoice id and sales_credit_note id in the allocated artefacts array. The amount can only be as large as the highest amount outstanding on either artefact. For example the SI outstanding amount = 10 and the SC outstanding amount = 20 the largest amount possible to allocate is 10.

Thanks

Mark

Screenshot 2023-12-06 at 11.42.06.png

Link to comment
Share on other sites

Sorry to bother you again- 

in this part of the artefacts id in which money is getting deducted-

image.png.ac39fdb6d56b815c4f9068da6c065291.png

the artefact_id is Credit Note id or contact_id?

I tried giving credit_note sage id like this-

image.png.c61dbf8f06d6ab542259538f23034fdf.png

but it's saying -  'A malformed request body was sent to the API.'
Thanks.

 

Edited by raghu Chaudhary
Link to comment
Share on other sites

Hi Raghu,

The transaction type = CUSTOMER_ALLOCATION. I've included an example body below where 387a3153269143aa9555ce8ad377eea2 = sales_invoice_id and 17ade05ce4674040a0742578308c20c0 = sales_credit_note_id.

The credit value needs to be signed -.

https://developer.sage.com/accounting/reference/payments/#tag/Contact-Allocations/operation/postContactAllocations

{
  "contact_allocation": {
    "transaction_type_id": "CUSTOMER_ALLOCATION",
    "contact_id": "2f0a9bdd56a548ffbac9380eba27ac19",
    "date": "2023-12-07",
    "allocated_artefacts": [
      {
        "artefact_id": "387a3153269143aa9555ce8ad377eea2",
        "amount": "162.25"
      },
      {
        "artefact_id": "17ade05ce4674040a0742578308c20c0",
        "amount": "-162.25"
      }
    ]
  }
  }

Thanks

Mark

Link to comment
Share on other sites

Hi Raghu,

The contact_allocation would need to be deleted in order to un-allocate the invoice and credit. The contact_allocation created from the above example is 19ef656e02a64d0eb8c0c06fb6fc87a4 so I would need to pass the below request to un-allocate.

DELETE https://api.accounting.sage.com/v3.1/contact_allocations/19ef656e02a64d0eb8c0c06fb6fc87a4

Thanks

Mark

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...