2

I'm trying to use the Netbanx API and i always get {"error":{"code":401,"message":"Not authorised"}} I dont know what I am doing wrong.

var url = "https://api.test.netbanx.com/hosted/v1/orders";
$.ajax({
    url: url,
    headers: { 
    "Authorization": "Basic " + btoa("devcentre4157:B-qa2-0-54b6431d-302c021451aabe02869ba82a4a4253d8b2a170d7950d228b021448948677e24be8180f945f1af2b583676c353b9f") 
    },
    type: 'POST',
    dataType: 'jsonp',
    contentType: 'application/json',
    data: "{merchantRefNum:'89983943',currencyCode:'CAD',totalAmount:'10'}",
    success: function (data) {
        alert(JSON.stringify(data));
    },
    error: function (err) {
        console.log(err);
    }
});
Amit
  • 45,440
  • 9
  • 78
  • 110

2 Answers2

1

I verified your code in and receive 401 as well.

Credentials is good, I did curl request and it's return data

curl -X POST -H "Content-Type: application/json" \
  -u devcentre4157:B-qa2-0-54b6431d-302c021451aabe02869ba82a4a4253d8b2a170d7950d228b021448948677e24be8180f945f1af2b583676c353b9f \
     https://api.test.netbanx.com/hosted/v1/orders \
  -d '{
          "merchantRefNum" : "89983943",
          "currencyCode"   : "CAD",
          "totalAmount"    : 10
      }'  

{"currencyCode":"CAD","id":"27HBQC4JI28QISA1LM","link":[{"rel":"hosted_payment","uri":"https://pay.test.netbanx.com/hosted/v1/payment/53616c7465645f5f9d3670f3f61d1664e3c0db218618a55369145e7577df013ab0691c526e56a445"},{"rel":"self","uri":"https://devcentre4157:B-qa2-0-54b6431d-302c021451aabe02869ba82a4a4253d8b2a170d7950d228b021448948677e24be8180f945f1af2b583676c353b9f@api.test.netbanx.com/hosted/v1/orders/27HBQC4JI28QISA1LM"},{"rel":"resend_callback","uri":"https://devcentre4157:B-qa2-0-54b6431d-302c021451aabe02869ba82a4a4253d8b2a170d7950d228b021448948677e24be8180f945f1af2b583676c353b9f@api.test.netbanx.com/hosted/v1/orders/27HBQC4JI28QISA1LM/resend_callback"}],"merchantRefNum":"89983943","mode":"live","totalAmount":10,"type":"order"}

I used DHC chrome plugin for one more check - it works as well. SO I am pretty sure there is Cross Domain problem with your JavaScript example. Netbanx just does not allow to do Cross Domain request to API.

enter image description here

Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46
  • Yeah i know thats is what the error code says but my credential are good. i have taken them from the my account page at developer.optimalpayments.com – Christian St-Gelais Sep 17 '15 at 20:34
  • you are correct - credentials is ok, I did curl and it's work. Maybe some cross site reference problem ? It's not a good idea to do request like this from the client javascript - you credentials is open. – Andriy Kuba Sep 17 '15 at 21:16
0

Normally in these situations the issue is how the key is encoded. it is posisble that when copying and pasting there are spaces at the beginning or end. The credentials do look valid.