Has anybody successfully created a Customer Paymen...
# suitetalkapi
g
Has anybody successfully created a Customer Payment and applied it to an Invoice with the SuiteTalk REST API? We have been struggling for months on this (our best guess is a busted Beta record?). Any help would be greatly appreciated.
b
what do your attempts look like
g
Thanks for the quick reply @battk! The request is:
PUT: https://{redacted}.<http://suitetalk.api.netsuite.com/services/rest/record/v1/customerpayment/eid:edc6916a-d59e-4f58-8eba-7313a526447c|suitetalk.api.netsuite.com/services/rest/record/v1/customerpayment/eid:edc6916a-d59e-4f58-8eba-7313a526447c>
Body:
Copy code
{
  "account": {
    "id": "217"
  },
  "apply": {
    "items": [
      {
        "amount": 57,
        "applyDate": "2020-11-14T03:58:19.668Z",
        "apply": true,
        "doc": {
          "id": "508405"
        },
        "type": "CustInvc"
      }
    ]
  },
  "createdDate": "2020-11-14T03:58:19.668Z",
  "customer": {
    "id": "51557"
  },
  "memo": "card 4242",
  "payment": 57,
  "tranDate": "2020-11-14T03:58:19.668Z"
}
b
that doesnt really look like an attempt that could succeed
usually you need to match to a key
and the keys arent objects
g
I'm fairly new to this, would you mind explaining more? What key would need to be matched? I'm making a very similar call via the SOAP api and it's working as expected.
b
i dont think you can call yourself new to something if you have been doing this for months
g
In the netsuite world, I think a few months is fairly new! But either way, I'd really appreciate your help if you think you know a solution.
b
you cant be lazy on this one, you really want to go though all the associated topics
g
We have tried to follow the documentation as best we can, and from what we can tell, we are following the request as it's expected here: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2021.1/index.html#/definitions/customerPayment-applyElement
There is no documentation on the
apply
list regarding any keys (we've actually looked into it and tried ourselves)
What would you recommend we use as the "key" in this instance? It seems that the "Working with Sublists" documentation and the "REST API Browser" documentation differ
b
they dont actually document which is the key
which usually means you get to play a guessing game
g
😂
b
ive yet to see a key that is a ns resource object
so its probably something else
g
ok so if we rule that out, the only other options would really be
line
(which we've tried),
type
(which we've tried) or the ref's
Copy code
{
  "account": {
    "id": "217"
  },
  "apply": {
    "items": [
      {
        "amount": 57,
        "applyDate": "2020-11-14T03:58:19.668Z",
        "apply": true,
        "doc": {
          "id": "508405"
        },
        "line": 0,
        "refNum": "test-ref-num",
        "refName": "test-ref-name",
        "total": 53.12,
        "type": "CustInvc"
      }
    ]
  },
  "createdDate": "2020-11-14T03:58:19.668Z",
  "customer": {
    "id": "51557"
  },
  "memo": "card 4242",
  "payment": 57,
  "tranDate": "2020-11-14T03:58:19.668Z"
}
I just tried that ^, trying to put all the values in it might be expecting but still no luck
b
i wouldnt go with doing everything at once
one at a time
g
just attempted one each, same error
b
have you tried the invoice transform?
g
I have not, I'm actually unsure what that is
I'm pretty sure the
Customer Payment
REST record is just broken in it's current form. We have spent a very long time trying to get this working and feel pretty confident in our data. I'm going to chalk this one up as a loss and going to revert back to SOAP for now...
It works without the apply list, but without the apply list it's useless
a
where did you find the format for the apply list?
a
from that article? something seems off about the 'items' list but I'm digging around too, I need to be able to accomplish this same thing
g
It looks like it would make sense if you compare the same working request in SOAP:
Copy code
<tranCust:applyList>
                    <tranCust:apply>
                        <tranCust:apply>true</tranCust:apply>
                        <tranCust:doc>578479</tranCust:doc>
                        <tranCust:applyDate>2020-12-03T02:50:22.000-08:00</tranCust:applyDate>
                        <tranCust:amount>565.83</tranCust:amount>
                    </tranCust:apply>
                </tranCust:applyList>
I would imagine that behind the scenes NetSuite is using the same backend logic for these requests regardless of SOAP or REST
so the fact that the apply list in SOAP containing just those few data points succeeds leads me to believe that REST should succeed as well
a
no 'items' array in the SOAP
b
id go for the transform from invoice to customer payment
the closest equivalent in suitescript is record.transform
a
yeah, very good idea, seeing some info in Answer Id: 91284
b
its similar, though not in execution, to soap's initialize operation
a
Gregg, have you tried simplifying as much as possible? maybe closer to
Copy code
{
  "customer": {
    "id": "51557"
  },
  "memo": "card 4242",
  "payment": 5,
  "apply": {
    "items": [
      {
        "line": 0,
        "amount": 5,
        "apply": true,
        "doc": {
          "id": "508405"
        }
      }
    ]
  }
}
if you're applying to invoice id 508405 - you can't adjust that it's a 'CustInv' or what it's total is - you also can't set created dates in NS
I could not mess with that payment's sublist no matter what I tried
however - the transform option worked quite well using just
Copy code
{
  "memo": "tester",
  "payment": 5,
  "autoapply": true
}
Copy code
/record/v1/invoice/220701/!transform/customerPayment
g
You absolutely can set created dates in NetSuite, we do this frequently with no problems. As far as simplifying the request, yes, we have tried every combination of payloads over the past few months. Item lists work fine in many other record types, just not in Customer Payments for whatever reason.
You also can adjust any of the properties you want so long as auto apply is not selected so long as you use the appropriate PUT or PATCH call to do so
This includes the document apply id as well
this can all be done via SOAP no problem, so the problem must reside in the Beta REST record implementation on their end
b
my testing so far suggests thats it is messed up
it looks like the key is the line
which fails because every line always has the line of 0
g
I've tried several combinations with the line number included....
b
so it basically only works when there is one invoice to apply
the transform worked fine
g
what do you mean 1 invoice to apply?
do you mean a 1-1 customer payment <> invoice relationship?
Because that's what our system has and it still doesn't work
b
if there is only 1 line in the apply sublist
g
That worked for you?! Can you please share your request body?
b
the second example you shared
with all the fields you wouldnt set in the ui removed
^ this one? This worked for you? We are receiving errors still with this...
b
again, customer with only 1 open invoice
g
oh only 1 open invoice on the customer side, I see
b
so that there is only 1 line on the apply sublist
i personally consider it an exercise in useless
the transform is more useful and controllable
g
the transform doesn't work well for our usecase
b
what about it doesnt work
g
we have many thousands of invoices and payments that are frequently updated from a backend service source of truth. We absolutely have to use the
UPSERT
operation with `eid`'s
b
probably best to live with soap unless you plan on keeping track of which customer payments have been created
g
unfortunately that's been our plan and what's in production since summer
I would hope after all of these years that eventually netsuite would release a true GA REST api
It doesn't appear they have made any progress on it in the last year or so
🤷‍♂️
523 Views