开发者

post request from native javascript to nestjs using axios

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
};
//Send a ping to Buyer Distribution platform
const res = await fetch('URL', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
        "Content-Type": "application/json"
    }
});

The code below is my BE开发者_运维技巧ST 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

  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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜