The goal is to migrate code that makes a post request.
The code being migrated comes from Zapier.
The code is being migrated to a nestjs app.
Zapier uses vanilla javascript.
the code used in zapier that makes a request is the following::
const data = {
"api_token": inputData.api_token,
"call_type": "Inbound",
"data": {
"zip": inputData.zip,
"phone": inputData.caller_number,
},
"placement_id": inputData.placement_id,
"sub_3": inputData.uuid,
"version": 17
};
const res = await fetch('URL', {
method: 'POST',
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
});
What I have tried:
The code below is my BEST attempt at making a post request in nestjs using HttpService..
note:: I removed " method: 'POST', " because we are using the "post" function. not sure if this is correct or not
<pre>
async postCallerInfoAndSetCallTransfers(incomingData) {
const data = {
api_token: incomingData.api_token,
call_type: 'Inbound',
data: {
zip: incomingData.zip,
phone: incomingData.number,
},
placement_id: incomingData.placement_id,
sub_3: incomingData.uuid,
version: 17,
};
const postConfig = {
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
};
const response = await this.httpService
.post('URL', postConfig)
.toPromise();
}
Did I translate that correctly? I currently can't hit the API as in I cant hit the original URL because its down for maintenance