question

hunter-dev avatar image
hunter-dev asked parquet76 answered

Clover eComm Hosted Checkout API Token Not Working - Getting 401-Unauthorized

I followed this guide. https://clover.github.io/hosted-checkout-codelab/walkthrough/adding-the-checkout-component/

Made sure everything is right but I'm getting the following response every time

{ "status" : {
"reason" : "Unauthorized" ,
"code" : 401
},
"message" : "Unauthorized"
}


I am using the correct API tokens according to the docs.

1727384961745.png

Here is the code I'm trying to get working

  async startCheckoutSession() {
    let authKey = 'Bearer ' + 'replace with Private Token';
    let mId = 'replace with Merchant Id';

    try {
      const checkoutSession = await fetch('https://sandbox.dev.clover.com/invoicingcheckoutservice/v1/checkouts', {
        method: 'POST',
        headers: {
          Authorization: authKey,
          'X-Clover-Merchant-ID': mId
        },
        body: JSON.stringify({
          "customer": {
            "email": "email@example.com",
            "firstName": "Example",
            "lastName": "Customer",
            "phoneNumber": "223-555-0002"
          },
          "shoppingCart": {
            "lineItems": [
              {
                "name": "Apple",
                "unitQty": 1,
                "price": 100
              },
              {
                "name": "Orange",
                "unitQty": 2,
                "price": 75
              }
            ]
          },
        })
      });

      const res = await checkoutSession.json();

      if (!checkoutSession.ok) {
        throw res;
      }

      window.location = res.href;

    }
    catch (e: any) {
      console.error(e);
    }
  }


Please help if you have an idea.

Do I need my developer account verified in order to make requests?

e-commerce api
1727384961745.png (33.5 KiB)
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

parquet76 avatar image
parquet76 answered

There is no approval on sandbox accounts. The merchant ID should be a13 character alphanumeric. Are you sure you are using the correct ID? Where are you making this request from the client or the server?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community