Successful fetch() but no content body

I am trying to make a fetch request to a 3rd party API that is for a delivery service. The request itself has valid headers and body. The expected response is a JSON object.

It works fine on reqbin.com .
On Wix, a fetch() is successful with no content body and a getJSON() gives an error

Reqbin request : Successful and response ok

Wix Code :

 fetch( "https://apis-staging.dunzo.in/api/v2/quote", {
        "method": "post",
        "headers": {
            'client-id': '<VALID-CLIENT-ID>',
            'Authorization': '<VALID-TOKEN>',
            'Accept-Language': 'en_US',
            'Content-Type': 'application/json'
        },
        "body": JSON.stringify({
            "pickup_details": [
            {
                "lat": 12.9672,
                "lng": 77.6721,
                "reference_id": "home"
            }
            ],
            "optimised_route": true,
            "drop_details": [
                {
                "lat": 12.96279,
                "lng": 77.63915,
                "reference_id": "office"
                }
            ],
            "delivery_type": "SCHEDULED",
            "schedule_time": 1650978119
        })
    })   
    .then(response => console.log('fetch success',response))
    .catch(err => console.log('Error : ',err)); 

Wix Fetch : Successful but no content body in return object

{
  "url": "https://apis-staging.dunzo.in/api/v2/quote",
  "status": 200,
  "statusText": "OK",
  "headers": {
    "_headers": {
      "date": [
        "Tue, 26 Apr 2022 10:00:23 GMT"
      ],
      "content-type": [
        "application/json"
      ],
      "content-length": [
        "100"
      ],
      "access-control-allow-headers": [
        "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization"
      ],
      "access-control-allow-methods": [
        "POST, GET, OPTIONS, PUT, DELETE, PATCH"
      ],
      "access-control-allow-origin": [
        "*"
      ],
      "server": [
        "dws"
      ],
      "via": [
        "1.1 google"
      ],
      "alt-svc": [
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
      ],
      "connection": [
        "close"
      ]
    }
  },
  "ok": true,
  "body": {
    "_readableState": {
      "objectMode": false,
      "highWaterMark": 16384,
      "buffer": {
        "head": {
          "data": {
            "type": "Buffer",
            "data": [
              123,
              34,
              100,
              105,
              115,
              116,
              97,
              110,
              99,
              101,
              34,
              58,
              53,
              46,
              52,
              44,
              34,
              101,
              115,
              116,
              105,
              109,
              97,
              116,
              101,
              100,
              95,
              112,
              114,
              105,
              99,
              101,
              34,
              58,
              53,
              57,
              44,
              34,
              101,
              116,
              97,
              34,
              58,
              123,
              34,
              112,
              105,
              99,
              107,
              117,
              112,
              34,
              58,
              49,
              53,
              44,
              34,
              100,
              114,
              111,
              112,
              111,
              102,
              102,
              34,
              58,
              51,
              53,
              125,
              44,
              34,
              100,
              114,
              111,
              112,
              95,
              111,
              114,
              100,
              101,
              114,
              34,
              58,
              91,
              34,
              97,
              112,
              97,
              114,
              110,
              97,
              45,
              104,
              111,
              117,
              115,
              101,
              34,
              93,
              125
            ]
          },
          "next": null
        },
        "tail": {
          "data": {
            "type": "Buffer",
            "data": [
              123,
              34,
              100,
              105,
              115,
              116,
              97,
              110,
              99,
              101,
              34,
              58,
              53,
              46,
              52,
              44,
              34,
              101,
              115,
              116,
              105,
              109,
              97,
              116,
              101,
              100,
              95,
              112,
              114,
              105,
              99,
              101,
              34,
              58,
              53,
              57,
              44,
              34,
              101,
              116,
              97,
              34,
              58,
              123,
              34,
              112,
              105,
              99,
              107,
              117,
              112,
              34,
              58,
              49,
              53,
              44,
              34,
              100,
              114,
              111,
              112,
              111,
              102,
              102,
              34,
              58,
              51,
              53,
              125,
              44,
              34,
              100,
              114,
              111,
              112,
              95,
              111,
              114,
              100,
              101,
              114,
              34,
              58,
              91,
              34,
              97,
              112,
              97,
              114,
              110,
              97,
              45,
              104,
              111,
              117,
              115,
              101,
              34,
              93,
              125
            ]
          },
          "next": null
        },
        "length": 1
      },
      "length": 100,
      "pipes": [],
      "flowing": null,
      "ended": true,
      "endEmitted": false,
      "reading": false,
      "sync": false,
      "needReadable": false,
      "emittedReadable": false,
      "readableListening": false,
      "resumeScheduled": false,
      "errorEmitted": false,
      "emitClose": true,
      "autoDestroy": true,
      "destroyed": false,
      "errored": null,
      "closed": false,
      "closeEmitted": false,
      "defaultEncoding": "utf8",
      "awaitDrainWriters": null,
      "multiAwaitDrain": false,
      "readingMore": false,
      "decoder": null,
      "encoding": null
    },
    "_events": {},
    "_eventsCount": 1,
    "_writableState": {
      "objectMode": false,
      "highWaterMark": 16384,
      "finalCalled": false,
      "needDrain": false,
      "ending": true,
      "ended": true,
      "finished": true,
      "destroyed": false,
      "decodeStrings": true,
      "defaultEncoding": "utf8",
      "length": 0,
      "writing": false,
      "corked": 0,
      "sync": false,
      "bufferProcessing": false,
      "writecb": null,
      "writelen": 0,
      "afterWriteTickInfo": null,
      "buffered": [],
      "bufferedIndex": 0,
      "allBuffers": true,
      "allNoop": true,
      "pendingcb": 0,
      "prefinished": true,
      "errorEmitted": false,
      "emitClose": true,
      "autoDestroy": true,
      "errored": null,
      "closed": false
    },
    "allowHalfOpen": true
  },
  "bodyUsed": false,
  "size": 0,
  "timeout": 0,
  "_raw": [],
  "_abort": false
}

Wix getJSON Result : Error

Error :  invalid json response body at https://apis-staging.dunzo.in/api/v2/quote reason: Unexpected end of JSON input

I have also tried response.json() and response.text(). They are both empty objects.

I new to HTTP requests but it seems like the server is responding with valid JSON on reqbin.com so what do i make of the above getJSON error?

Also I’ve tested this on preview and live site. Same result

...///
.then(response => response.json())
.then(bodyJson => console.log(bodyJson));

Works! Thank you

Thank You so much!

1 Like