cancel
Showing results for 
Search instead for 
Did you mean: 

E00124 : The provided access token is invalid

I am using the code below but continually get the error. I am not sure what I am doing incorrectly. I assume I need to create a certificate first but not clear in the samples. Any help would be greatly appreciated. New to the .Net API. Thanks in advance.

 

VB.Net

 

Imports System.Net
Imports System.IO
Imports AuthorizeNet.Api.Controllers
Imports AuthorizeNet.Api.Contracts.V1
Imports AuthorizeNet.Api.Controllers.Bases
 
Partial Class AIM_Test 
Inherits System.Web.UI.Page   Public Function Run(ApiLoginID As [String], ApiTransactionKey As [String], amount As Decimal) As ANetApiResponse System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 lblResponse.Text = "Charge Credit Card Sample"   ApiOperationBase(Of ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX   ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType()   Dim merchantAuthenticationType = New merchantAuthenticationType() merchantAuthenticationType.name = ApiLoginID merchantAuthenticationType.ItemElementName = ItemChoiceType.transactionKey merchantAuthenticationType.Item = ApiTransactionKey Dim creditCard = New creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "0718" creditCard.cardCode = "123" creditCard.isPaymentToken = True creditCard.cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=" ' GOT THIS FROM THE SAMPLE ON AUTHORIZE.Net, WAS Not in original sample but tried it to see if it helps. Dim billingAddress = New customerAddressType() billingAddress.firstName = "John" billingAddress.lastName = "Doe" billingAddress.address = "123 My St" billingAddress.city = "OurTown" billingAddress.zip = "98004"
'standard api call to retrieve response Dim paymentType = New paymentType() paymentType.Item = creditCard
' charge the card Dim transactionRequest = New transactionRequestType() transactionRequest.transactionType = transactionTypeEnum.authCaptureTransaction.ToString() transactionRequest.amount = amount transactionRequest.payment = paymentType transactionRequest.billTo = billingAddress Dim request = New createTransactionRequest() request.transactionRequest = transactionRequest ' instantiate the contoller that will call the service Dim controller = New createTransactionController(request) controller.Execute()
' get the response from the service (errors contained if any) Dim response = controller.GetApiResponse()
'validate If response IsNot Nothing Then If response.messages.resultCode = messageTypeEnum.Ok Then If response.transactionResponse.messages IsNot Nothing Then lblResponse.Text = "Successfully created transaction with Transaction ID: " + response.transactionResponse.transId lblResponse.Text = lblResponse.Text & "<br/>Response Code: " + response.transactionResponse.responseCode lblResponse.Text = lblResponse.Text & "<br/>Message Code: " + response.transactionResponse.messages(0).code lblResponse.Text = lblResponse.Text & "<br/>Description: " + response.transactionResponse.messages(0).description lblResponse.Text = lblResponse.Text & "<br/>Success, Auth Code : " + response.transactionResponse.authCode Else lblResponse.Text = "Failed Transaction." If response.transactionResponse.errors IsNot Nothing Then lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText End If End If Else lblResponse.Text = "Failed Transaction." If response.transactionResponse IsNot Nothing AndAlso response.transactionResponse.errors IsNot Nothing Then lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText Else lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.messages.message(0).code lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.messages.message(0).text End If End If Else lblResponse.Text = "Null Response." End If
Return response End Function   End Class

 

 

Returns: E00124 : The provided access token is invalid

nathan0103
Member
2 ACCEPTED SOLUTIONS

Accepted Solutions

@nathan0103 wrote:

First I started with a simple card proccess. The 2 lines you mentioned were omitted. I got the error so I dug around and found I needed a tokenized transaction so I added those lines. Either way with them there or not, I get the same error. 


I just want to make sure I'm reading this correctly. You're saying that without those two lines, you still get error E00124? That would be very strange.

 

E00124 refers to an "access token", so it doesn't really have anything to do with tokenized transactions. Instead it's access control to our system in cases where you might be performing a transaction on behalf of someone else (like using OAuth). With just you doing a simple transaction with your own login ID and transaction key, you shouldn't every see that error.

 

I don't see any obvious flaws in the code. I'm grasping at straws and shooting in the dark here (among other metaphors), but can you try a few things and let us know if anything changes?

 

1. Just verifying that you ran the code in the API Reference on our site using your keys, correct? And it worked there, correct? Which specific sample or function were you trying there?

2. Have you tried our sample C# code on GitHub, like this simple charge sample? Anything different with that?

3. Can you log into the merchant interface for your sandbox account and generate a new transaction key and try that?

4. How about a different sandbox account? Could you possibly create a new sandbox account to see if anything's isolated to the specific account you're using?

View solution in original post

Aaron,

    You Rock, thank you. It was all me, I 'mis-transposed' the c# to VB. I was creating a new key of merchantAuthenticationType and not including it as part of the ApiOperationBase. It was not until I recreated the C# and got it working that I knew it was something stupid I was missing. Been coding over 20 years C+ VB Java and SQL are my main am a little rusty with the newer C#. Again I knew it had to be something I missed thanks. I have posted to full VB.Net working code below for anyone in the future. Thanks again for the direction, that is what made me see it.

 

 

Public Function Run(ApiLoginID As String, ApiTransactionKey As String, amount As Decimal) As ANetApiResponse
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

        lblResponse.Text = "Charge Credit Card Sample"

        ApiOperationBase(Of ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX


'==========NEEDED THIS INSTEAD TO INCLUDE==============

        ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType() With {
            .name = ApiLoginID,
            .ItemElementName = ItemChoiceType.transactionKey,
            .Item = ApiTransactionKey
        }


'==========NEEDED THIS INSTEAD TO INCLUDE==============



'========THIS IS WHERE THE ERROR WAS======================


        'ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType()

        'Dim merchantAuthenticationType = New merchantAuthenticationType()
        'merchantAuthenticationType.name = ApiLoginID
        'merchantAuthenticationType.ItemElementName = ItemChoiceType.transactionKey
        'merchantAuthenticationType.Item = ApiTransactionKey

'========THIS IS WHERE THE ERROR WAS======================




        '#Region "Payment Information"
        Dim creditCard = New creditCardType()
        creditCard.cardNumber = "4111111111111111"
        creditCard.expirationDate = "0722"
        creditCard.cardCode = "456"


        Dim billingAddress = New customerAddressType()
        billingAddress.firstName = "John"
        billingAddress.lastName = "Doe"
        billingAddress.address = "123 My St"
        billingAddress.city = "OurTown"
        billingAddress.zip = "98006"

        'standard api call to retrieve response
        Dim paymentType = New paymentType()
        paymentType.Item = creditCard


        '' Add line Items
        'Dim lineItems = New lineItemType(1) {}
        'lineItems(0) = New lineItemType() With {
        '        Key.itemId = "1",
        '        Key.name = "t-shirt",
        '        Key.quantity = 2,
        '        Key.unitPrice = New [Decimal](15.0)
        '    }
        'lineItems(1) = New lineItemType() With {
        '        Key.itemId = "2",
        '        Key.name = "snowboard",
        '        Key.quantity = 1,
        '        Key.unitPrice = New [Decimal](450.0)
        '    }

        ' charge the card
        Dim transactionRequest = New transactionRequestType()
        transactionRequest.transactionType = transactionTypeEnum.authCaptureTransaction.ToString()
        transactionRequest.amount = amount
        transactionRequest.payment = paymentType
        transactionRequest.billTo = billingAddress
        'transactionRequest.lineItems = lineItems


        Dim request = New createTransactionRequest()
        request.transactionRequest = transactionRequest


        ' instantiate the contoller that will call the service
        Dim controller = New createTransactionController(request)
        controller.Execute()

        ' get the response from the service (errors contained if any)
        Dim response = controller.GetApiResponse()

        'validate
        If response IsNot Nothing Then
            If response.messages.resultCode = messageTypeEnum.Ok Then
                If response.transactionResponse.messages IsNot Nothing Then
                    lblResponse.Text = "Successfully created transaction with Transaction ID: " + response.transactionResponse.transId
                    lblResponse.Text = lblResponse.Text & "<br/>Response Code: " + response.transactionResponse.responseCode
                    lblResponse.Text = lblResponse.Text & "<br/>Message Code: " + response.transactionResponse.messages(0).code
                    lblResponse.Text = lblResponse.Text & "<br/>Description: " + response.transactionResponse.messages(0).description
                    lblResponse.Text = lblResponse.Text & "<br/>Success, Auth Code : " + response.transactionResponse.authCode
                Else
                    lblResponse.Text = "Failed Transaction."
                    If response.transactionResponse.errors IsNot Nothing Then
                        lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode
                        lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText
                    End If
                End If
            Else
                lblResponse.Text = "Failed Transaction."
                If response.transactionResponse IsNot Nothing AndAlso response.transactionResponse.errors IsNot Nothing Then
                    lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode
                    lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText
                Else
                    lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.messages.message(0).code
                    lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.messages.message(0).text
                End If
            End If
        Else
            lblResponse.Text = "Null Response."
        End If

        Return response
    End Function

 

View solution in original post

7 REPLIES 7

Check to ensure you are using the appropriate LoginID and TransactionKey for the Sandbox and the ApiLoginID and ApiTransactionKey Strings reflect these.

Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

Thanks for the reply. Unfortunately that is not the issue. I have checked that multiple times. My Login and TKey both work with AIM so I know they are good. Do I need different ones for the .Net API? Am I missing a field? I have scoured the internet and have tried refid market type and a few other things to no avail. I am at a loss but I must be missing something simple. Thanks again for any assistance.

Hi @nathan0103,

 

Can you explain a little bit about what you're trying to do? Are you just trying to process a card, or actually trying to work with tokenized payments? If you're actually trying to process tokens, you generally need to get a fresh token for each request.

 

If you're just trying to charge a card, remove the creditCard.isPaymentToken and creditCard.cryptogram lines.

Aaron, thanks for the reply. Well I am trying to get anything to work to start. First I started with a simple card proccess. The 2 lines you mentioned were omitted. I got the error so I dug around and found I needed a tokenized transaction so I added those lines. Either way with them there or not, I get the same error. So my goal is to move from the AIM api to the new .Net api. I want to use subscriptions as well but the sample code supplied gives the same error. I can not get past this error no matter how I code it. So I need to get past this error first before I can even attempt the token transaction if needed. I plug my API keys into the sample on the Authorixe.net site and click run sample and it goes through but if I copy and paste the provided code even in C# on my box it gives this error. I must be missing something simple but just can not determine what as this error is too generic. Thanks in advance for any help, as I am completely stuck at this point and can not figure out why.


@nathan0103 wrote:

First I started with a simple card proccess. The 2 lines you mentioned were omitted. I got the error so I dug around and found I needed a tokenized transaction so I added those lines. Either way with them there or not, I get the same error. 


I just want to make sure I'm reading this correctly. You're saying that without those two lines, you still get error E00124? That would be very strange.

 

E00124 refers to an "access token", so it doesn't really have anything to do with tokenized transactions. Instead it's access control to our system in cases where you might be performing a transaction on behalf of someone else (like using OAuth). With just you doing a simple transaction with your own login ID and transaction key, you shouldn't every see that error.

 

I don't see any obvious flaws in the code. I'm grasping at straws and shooting in the dark here (among other metaphors), but can you try a few things and let us know if anything changes?

 

1. Just verifying that you ran the code in the API Reference on our site using your keys, correct? And it worked there, correct? Which specific sample or function were you trying there?

2. Have you tried our sample C# code on GitHub, like this simple charge sample? Anything different with that?

3. Can you log into the merchant interface for your sandbox account and generate a new transaction key and try that?

4. How about a different sandbox account? Could you possibly create a new sandbox account to see if anything's isolated to the specific account you're using?

Aaron,

    You Rock, thank you. It was all me, I 'mis-transposed' the c# to VB. I was creating a new key of merchantAuthenticationType and not including it as part of the ApiOperationBase. It was not until I recreated the C# and got it working that I knew it was something stupid I was missing. Been coding over 20 years C+ VB Java and SQL are my main am a little rusty with the newer C#. Again I knew it had to be something I missed thanks. I have posted to full VB.Net working code below for anyone in the future. Thanks again for the direction, that is what made me see it.

 

 

Public Function Run(ApiLoginID As String, ApiTransactionKey As String, amount As Decimal) As ANetApiResponse
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

        lblResponse.Text = "Charge Credit Card Sample"

        ApiOperationBase(Of ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX


'==========NEEDED THIS INSTEAD TO INCLUDE==============

        ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType() With {
            .name = ApiLoginID,
            .ItemElementName = ItemChoiceType.transactionKey,
            .Item = ApiTransactionKey
        }


'==========NEEDED THIS INSTEAD TO INCLUDE==============



'========THIS IS WHERE THE ERROR WAS======================


        'ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType()

        'Dim merchantAuthenticationType = New merchantAuthenticationType()
        'merchantAuthenticationType.name = ApiLoginID
        'merchantAuthenticationType.ItemElementName = ItemChoiceType.transactionKey
        'merchantAuthenticationType.Item = ApiTransactionKey

'========THIS IS WHERE THE ERROR WAS======================




        '#Region "Payment Information"
        Dim creditCard = New creditCardType()
        creditCard.cardNumber = "4111111111111111"
        creditCard.expirationDate = "0722"
        creditCard.cardCode = "456"


        Dim billingAddress = New customerAddressType()
        billingAddress.firstName = "John"
        billingAddress.lastName = "Doe"
        billingAddress.address = "123 My St"
        billingAddress.city = "OurTown"
        billingAddress.zip = "98006"

        'standard api call to retrieve response
        Dim paymentType = New paymentType()
        paymentType.Item = creditCard


        '' Add line Items
        'Dim lineItems = New lineItemType(1) {}
        'lineItems(0) = New lineItemType() With {
        '        Key.itemId = "1",
        '        Key.name = "t-shirt",
        '        Key.quantity = 2,
        '        Key.unitPrice = New [Decimal](15.0)
        '    }
        'lineItems(1) = New lineItemType() With {
        '        Key.itemId = "2",
        '        Key.name = "snowboard",
        '        Key.quantity = 1,
        '        Key.unitPrice = New [Decimal](450.0)
        '    }

        ' charge the card
        Dim transactionRequest = New transactionRequestType()
        transactionRequest.transactionType = transactionTypeEnum.authCaptureTransaction.ToString()
        transactionRequest.amount = amount
        transactionRequest.payment = paymentType
        transactionRequest.billTo = billingAddress
        'transactionRequest.lineItems = lineItems


        Dim request = New createTransactionRequest()
        request.transactionRequest = transactionRequest


        ' instantiate the contoller that will call the service
        Dim controller = New createTransactionController(request)
        controller.Execute()

        ' get the response from the service (errors contained if any)
        Dim response = controller.GetApiResponse()

        'validate
        If response IsNot Nothing Then
            If response.messages.resultCode = messageTypeEnum.Ok Then
                If response.transactionResponse.messages IsNot Nothing Then
                    lblResponse.Text = "Successfully created transaction with Transaction ID: " + response.transactionResponse.transId
                    lblResponse.Text = lblResponse.Text & "<br/>Response Code: " + response.transactionResponse.responseCode
                    lblResponse.Text = lblResponse.Text & "<br/>Message Code: " + response.transactionResponse.messages(0).code
                    lblResponse.Text = lblResponse.Text & "<br/>Description: " + response.transactionResponse.messages(0).description
                    lblResponse.Text = lblResponse.Text & "<br/>Success, Auth Code : " + response.transactionResponse.authCode
                Else
                    lblResponse.Text = "Failed Transaction."
                    If response.transactionResponse.errors IsNot Nothing Then
                        lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode
                        lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText
                    End If
                End If
            Else
                lblResponse.Text = "Failed Transaction."
                If response.transactionResponse IsNot Nothing AndAlso response.transactionResponse.errors IsNot Nothing Then
                    lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.transactionResponse.errors(0).errorCode
                    lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.transactionResponse.errors(0).errorText
                Else
                    lblResponse.Text = lblResponse.Text & "<br/>Error Code: " + response.messages.message(0).code
                    lblResponse.Text = lblResponse.Text & "<br/>Error message: " + response.messages.message(0).text
                End If
            End If
        Else
            lblResponse.Text = "Null Response."
        End If

        Return response
    End Function

 

Phew, really glad there was a solution in there somewhere. If nothing worked on your end I was really worried about how deep I might have to dig to find the bug on our end.

 

My VB's rusty enough that I didn't catch the error in the code. I was just seeing, "hmm, that's the right name and type" and moving on. So, I'll claim no credit in helping you solve this, but I'm extremely glad it worked out.