I keep getting a 500 response code in an API call to the Cardpointe gateway (cardconnect) any insight will help.
(I was able to verify the test credentials by just posting to the URL without the auth
endpoint)
Here is my code in a Google apps script:
function myFunction() {
var messagesUrl = "https://fts-uat.cardconnect.com/cardconnect/rest/auth";
var cred = "testing:testing123";
var payload = JSON.stringify({
"merchid" : "496160873888",
"account": "4788250000121443",
"expiry": "1218",
"cvv2": "123",
"amount": "100",
"phone": "15558889999",
"capture": "y"
});
var options = {
"method" : "put",
"payload" : payload
};
options.headers = {
"Authorization" : "Basic " Utilities.base64Encode(cred)
},{
"Content-Type" : "application/json"
}
var res = UrlFetchApp.fetch(messagesUrl, options);
Logger.log(res);
}
CodePudding user response:
options.headers = {
"Authorization" : "Basic " Utilities.base64Encode(cred)
},{
"Content-Type" : "application/json"
}
Here content type is not set to options.headers
.
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
const options ={};
options.headers = {
"Authorization" : "Basic " "b64"
},{
"Content-Type" : "application/json"
}
console.log(options)
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>
headers
should be a single object with multiple keys:
options.headers = {
"Authorization" : "Basic " Utilities.base64Encode(cred),
"Content-Type" : "application/json"
}
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
const options={}
options.headers = {
"Authorization" : "Basic " "b64",
"Content-Type" : "application/json"
}
console.log(options)
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
let a;
a = 1,3;
console.log(a);// no 3
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>