I am tasked with a bespoke integration with a 3rd ...
# suitescript
s
I am tasked with a bespoke integration with a 3rd party who's API for a particular action only supports "PATCH" not "PUT" or "POST". Anyone know of a way to successfully do a "PATCH" method? We have already tried to include
headers: { 'X-HTTP-Method-Override': 'PATCH'}
but it is not recognised in the other system.
b
need to make something else send the patch
s
which libraries can support a server side https call?
b
something else as in a different application server
👀 1
suitescript cant send patches
👍 1
a
PATCH is just a subset of PUT... its less efficient but you can just use all PUTS you just have to send all the data elements everytime
Copy code
3rd party server object exists as
{
   id: 1001,
   name: 'abc',
   foo: 1,
   bar: 17
}

if you were to do a PATCH

{
   id: 1001,
   name 'def'
}

the object would update to 
{
    id: 1001,
    name 'def',
    foo: 1,
    bar: 17
}

if you wanted that same result with PUT you'd have to send

{
   id: 1001,
   name: 'def',
   foo: 1,
   bar: 17
}

that is to say you have to include all the data elements even those ones you're not updating because otherwise those elements get wiped out completely.

so if you PUT

{
   id: 1001,
   name 'def'
}

then that's exactly what the obj would be when you're done
it would have a foo or bar value at all
b
ignore the discussion on how a restful service should behave
suitescript cannot send a patch
a
I didn't contradict you? your solution was, use something other than NetSuite, my alternative is don't use PATCH and you can use NetSuite 🙂
b
that is true, convince the 3rd party to implement put or post instead is an option
a
oh i totally misread the first post, my bad, I retract my statements, I read it as they ONLY allow POST/PUT/PATCH
a
Can you create a suitelet, have that call the api using XMLHttpRequest with patch, and use the response in your script?
s
Getting a CORS policy error
a
Do you have a request working when trying it through something like postman?
s
yes
a
Without knowing how your responses look like I would guess doing this way probably won't work. If you see the Access-Control-Allow-Methods in the response header it might not have PATCH in the list. CORS could also not allowed on all requests to the api.
s
The 3rd party API actively blocks client-side calls, so it has to be a server-side call
n
You might have to rely on middleware, not suggesting what to use, we tend to build our own in AWS. Have NS call AWS, AWS makes the call to the 3rd party. It can get messy but if you have to use PATCH and you have to do it serverside, that's looking like the route you need to go.
s
In a very happy end to the day, i was able to work out how to use AWS Lambda functions to act as a proxy server.... with success!!!! happy day!
👍 1
👍🏻 1