I'm trying to post a registration card thanks to Mangopay API (here is the Postcard route info: https://docs.mangopay.com/endpoints/v2.01/cards#e1042_post-card-info)
fetch(cardRegistration.CardRegistrationURL, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: new URLSearchParams({
accessKeyRef: accessKeyRef,
data: data,
cardNumber: cardNumber,
cardExpirationDate: expiration,
cardCvx: cvx,
}).toString(),
});
I have a 200 status when I post on this url (https://homologation-webpayment.payline.com/webpayment/getToken) but I can't get data through response.json() and I don't understand why.
Here is the response I get :
{
"type": "default",
"status": 200,
"ok": true,
"statusText": "",
"headers": {
"map": {
"server": "Apache",
"connection": "Keep-Alive",
"access-control-allow-origin": "*",
"keep-alive": "timeout=15, max=100",
"date": "Wed, 22 Sep 2021 15:21:11 GMT",
"vary": "Accept-Encoding,User-Agent",
"content-length": "155",
"content-type": "text/plain"
}
},
"url": "https://homologation-webpayment.payline.com/webpayment/getToken",
"bodyUsed": false,
"_bodyInit": {
"_data": {
"size": 155,
"offset": 0,
"blobId": "415DAFF0-5B8F-429E-91F2-4FC94765A2C2",
"type": "text/plain",
"name": "getToken.txt",
"__collector": {}
}
},
"_bodyBlob": {
"_data": {
"size": 155,
"offset": 0,
"blobId": "415DAFF0-5B8F-429E-91F2-4FC94765A2C2",
"type": "text/plain",
"name": "getToken.txt",
"__collector": {}
}
}
}
But I can't continue after calling the JSON method on it.
let card = await postCardResponse.json()
console.log('hello')
The console will never show 'hello'.
I tried on postman and I have no problem. However, I am not getting a json but a simple text 'data = ....'. How to retrieve this data via the code?
Thanks in advance.
I found the solution. You simply have to use response.text() instead of response.json()..