hey all, has anyone batched invoices into a single...
# suitetalkapi
j
hey all, has anyone batched invoices into a single customer payment using the REST API?
b
will probably involve transforming a customer into a customer payment
and then changing the apply field of the apply sublist on each matching invoice
j
yeah that’s what i tried to do, but i’m having trouble structuring the request.
oh interesting, so the apply sublist is on the invoice and not the customer payment?
here’s how i tried to create/transform a customer payment:
POST {{REST_SERVICES}}/record/v1/customerpayment
Copy code
{
  "customer": {
    "id": 150
  },
  "apply": {
    "items": [
      {
        "amount": 368.93,
        "apply": "T",
        "applyDate": "2020-08-01",
        "createdFrom": 4960,
        "due": 368.93,
        "refNum": "INV15",
        "total": 368.93
      }
    ]
  }
}
b
a customer payment will have an array of items
use the customer to customer payment transform to initialize the apply item array
and set the apply checkbox to T on the items you want to apply
j
i see. so does something like this make sense?
POST {{REST_SERVICES}}/record/v1/customer/150/!transform/customerpayment
with body:
Copy code
{
  "apply": {
    "items": [
      {
        "amount": 368.93,
        "apply": "T",
        "applyDate": "2020-08-01",
        "createdFrom": 4960,
        "due": 368.93,
        "refNum": "INV15",
        "total": 368.93
      }
    ]
  }
}
e..g do it all in a single request
b
probably depends on what the key for items are
you would need that field set to match what would be on the customer payment
j
hm let me back up for a sec. i generated a customer payment from a customer and now i want to update the apply -> items sublist
getting the following error here:
Copy code
"title": "Error while accessing resource: You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.",
b
that would be the key thing
your item needs to match an existing line, and the matching is done by the key
j
oh i think i get it
so when you go cust -> cust payment, it initailizes the payment with items sublist populated with all the outstanding invoices from that cust
b
j
so if i want to update the items sublist, it has to reflect the existing items
got it
b
the key is probably the doc element
j
yeah i’m trying to figre out the key right now
message has been deleted
i imagine it’s the refNum, e.g. INV-15
b
unlikely, thats the transaction id/document number, which is not actually required to be unique
j
ah i see. well there’s a bug with expandSubresources on customer payments so i was relying on the documentation to see what’s returned in the apply items sublist
in the UI i see that i might have access to internal id like so:
b
out with the old and in with the new: customerPayment-applyElement
alternatively use the metadata from the webservice, which should be better than the documentation
j
wow!
lifesaver. thanks
so i’m very close to patching a cust payment, but running into an issue with the doc field, which should be available according to the customerpayment apply element:
b
use the internal id
in the id key
j
when i use this, i get the same error:
Copy code
{
  "apply": {
    "items": [
      {
        "doc": {
          "id": "4960"
        },
        "due": 4
      }
    ]
  }
}
when i run this, i get the previous error about invalid sublist/item:
Copy code
{
  "apply": {
    "items": [
      {
        "id": "4960",
        "due": 4
      }
    ]
  }
}
b
is 4960 an internal id available to be paid for that customer?
and while not a problem now, you probably want amount instead of due
j
yeah should be. i just applied the checkmark here and was able to save it:
^that’s internal id 4960
b
unfortunatly for you,
Copy code
{
  "apply": {
    "items": [
      {
        "apply": true,
        "doc": {
          "id": "171"
        },
        "amount": 0.01
      }
    ]
  }
}
works for me
j
and did you use a PATCH request with
?replace=apply
?
b
huh
thats post only
that said, you cant replace lines in a customer payment, only update
j
i see
yeah i’m not sure why it’s not working for me.
"Invalid sublist line key doc in request body."
seems like it doesn’t like the field doc, but i can’t find anything about that error message online
b
are you trying to update or create a new customer payment
j
i’ve tried both. patching an existing cust payment as well as creating a new one from a transformation as you did above. it’s almost like the api is stuck in a prev version that doesn’t support a doc key
always the same error about the invalid sublist line key
b
could potentially be a beta thing
i can at least say it works for me on 2020.2
j
i wonder if i have to specify an upgrade
b
you currently have no choice
its whatever version your netsuite account is on
j
huh
when i query the meta catalog, this is the entry for cust payment apply element:
Copy code
"customerPayment-applyElement": {
                "type": "object",
                "properties": {
                    "links": {
                        "title": "Links",
                        "type": "array",
                        "readOnly": true,
                        "items": {
                            "$ref": "#/components/schemas/nsLink"
                        }
                    },
                    "discDate": {
                        "title": "Disc. Date",
                        "type": "string",
                        "format": "date",
                        "nullable": true
                    },
                    "amount": {
                        "title": "Payment",
                        "type": "number",
                        "format": "double",
                        "nullable": true
                    },
                    "apply": {
                        "title": "Apply",
                        "type": "boolean"
                    },
                    "line": {
                        "type": "integer",
                        "format": "int64",
                        "nullable": true
                    },
                    "createdFrom": {
                        "type": "string",
                        "nullable": true
                    },
                    "discAmt": {
                        "title": "Disc. Avail.",
                        "type": "number",
                        "format": "double",
                        "nullable": true
                    },
                    "internalId": {
                        "title": "Internal ID",
                        "type": "string",
                        "nullable": true
                    },
                    "total": {
                        "title": "Orig. Amt.",
                        "type": "number",
                        "format": "double",
                        "nullable": true
                    },
                    "applyDate": {
                        "title": "Date",
                        "type": "string",
                        "format": "date",
                        "nullable": true
                    },
                    "refNum": {
                        "title": "Ref No.",
                        "type": "string",
                        "nullable": true
                    },
                    "due": {
                        "title": "Amt. Due",
                        "type": "number",
                        "format": "double",
                        "nullable": true
                    },
                    "dueDate": {
                        "type": "string",
                        "format": "date",
                        "nullable": true
                    },
                    "disc": {
                        "title": "Disc. Taken",
                        "type": "number",
                        "format": "double",
                        "nullable": true
                    },
                    "refName": {
                        "title": "Reference Name",
                        "type": "string",
                        "readOnly": true
                    }
                },
                "description": "This record is available as a beta record.",
                "x-ns-filterable": [],
                "x-ns-support-level": "beta"
            }
        },
there is no doc element, nor is there currency, parenttransaction, or others i see in 2020.2
b
given that metadata, i would use internalId
j
yeah i’d love to, but i’m getting the same ol error again
i’m gonna try to upgrade my env to 2020.2
b
InternalId vs id?
j
sadly doesn’t work either
i’m going to try upgrading our version of netsuite since i’m pretty sure we’re on an older version. we don’t have the invoice grouping feature available in our sandbox, which might actually make all of this way easier
NetSuite (Edition: Canada) Release 2020.1
yup our sandbox is running on the older version
BTW @battk:
works with 2020.2 🙂