Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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::

JavaScript
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
};
//Send a ping to Buyer Distribution platform
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, // fix: verify if this is caller_number or number. on the original text that dylan send me it was caller_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(); // fix: toPromise is deprecated

  }

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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900