summaryrefslogtreecommitdiff
path: root/src/pages/api/biteship-service.js
blob: ed9e2a9f850830ac01ee14cb7e0c403fccb31cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import biteShipAPI from '../../core/api/biteShip';

export default async function handler(req, res) {
  const { body } = req.query;

  const parsedBody = JSON.parse(body);
  console.log(parsedBody);

  try {
    let result = await biteShipAPI('POST', '/v1/rates/couriers', parsedBody);
    console.log('ini result', result);

    if (result && result.data && result.data.data) {
      res.status(200).json(result.data.data);
    } else {
      res
        .status(500)
        .json({ error: 'Unexpected response structure from Biteship API' });
    }
  } catch (error) {
    console.error('Error:', error);
    res.status(400).json({ error: error.message });
  }
}