Error calling CreateCustomerCard

So I can add a customer to square using the API and C#.  When I add a card to the customer I get this error: 

 

Error calling CreateCustomerCard: {"errors":[{"category":"AUTHENTICATION_ERROR","code":"UNAUTHORIZED","detail":"Your request did not include an `Authorization` http header with an access token. The header value is expected to be of the format \"Bearer TOKEN\" (without quotation marks), where TOKEN is to be replaced with your access token (e.g. \"Bearer ABC123def456GHI789jkl0\"). For more information, see https://docs.connect.squareup.com/api/connect/v2/#requestandresponseheaders. If you are seeing this error message while using one of our officially supported client libraries, please report this to [email protected]. "}]}

 

 

Code below (try-catch removed for readability):

 

 

            CustomerCardApi ca = new CustomerCardApi();

            Customer cst = new Customer(txtsquarecustid.Value);

            string n = cardNonce.Value;

       

 

            Address address = new Address(AddressLine1: txtshipaddress1.Value, PostalCode: txtshipzip.Value);

            CreateCustomerCardRequest b = new CreateCustomerCardRequest(n, address, txtclientname.Value);

 

            CreateCustomerCardResponse resp = ca.CreateCustomerCard(_accessToken, squarecustid, b);

 

            JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(resp.ToJson().ToString());

 

          

            cardid = (string)jObject["card"]["id"];

 

Tags (1)
3,099 Views
Message 1 of 3
Report
1 Solution

Solution

I solved it – apparently the variable I used for customerid was not initialized.

 

View Solution >

4,043 Views
Message 2 of 3
Report
2 REPLIES 2

Solution

I solved it – apparently the variable I used for customerid was not initialized.

 

4,044 Views
Message 2 of 3
Report
Square

@ResultsNation - Glad to hear, and thanks for reporting back! 


Sean
he/him/his
Product Manager | Square, Inc.
3,090 Views
Message 3 of 3
Report