1. Home
  2. Generate access token

Generate access token

The authentication service is mainly used to obtain the token which will be used to stamp our CFDI (xml) already issued, In order to use this service, it is necessary that you have a username and a password to receive the token.

To use any of our services it is a must to have an access token. This token can be obtained in two ways:

Get token through username and password

In this section, we will show how to carry out the authentication and token generation, through our libraries and services.

Authenticate using API services

Test environment url

http://services.test.sw.com.mx/security/authenticate

Production environment url

http://services.sw.com.mx/security/authenticate

Authentication example using auth service:

Response example:

Authenticate using our libraries

You can also authenticate using our libraries, which includes c#, java, delphi, php and so on.

This is an authentication example using our java library and the Eclipse IDE. You can get the sdk library here.

  1. Create eclipse project.
  2.  Import library to our project. In order to do this, go to the top menu and look for “project” → “Properties” and in the new window we will go to “Java Build Path” → “Libraries” → “Add External JARs …” and select the library.
  3. Create a new class.
  4. Use the the authentication function available in the sdk library.

     

Our services always return a “status”, which can be “success” or “error”.

In case we get a “status” different to  “success” we will print the variables of the response object: the “message” and “messageDetail” which will tell us the error detail (example “Unauthorized”).

If our status is a “success”, we will print the token in the console, to verify that it works correctly.

This is the code example.

Get expireless token

Sometimes, for reasons of efficiency and speed of your application or system, you may not want to authenticate yourself and generate a token for each invoice (cfdi) that you send to stamp. For this case we have a token without expiration. To generate it follow the next steps.

  • Step 1. Go to the stamps manager (Administrador de timbres) provided by SW sapien. 
Production environment

http://cliente.smartweb.com.mx/

  • Step 2. Enter your credentials (username and password) to login or  use the demo account for testing purposes:

Username: demo

Password: 123456789

  • Step 3. Once logged in, go to the top right corner section and click the gear icon
  • Step 4. Click the option “Credenciales de acceso” (access credentials)
  • Step 5. At that point you will already have your “expireless token” generated and you can use the copy (“Copiar”) button or copy the text manually to use it when you consume the SW smarter services.
    IMPORTANT

    The expireless token is obtained through the SW smarter Administration web application where you can generate it and then use it when you consume the SW smarter services. When you revoke or regenerate the token you must have to update the token in your application.To get the token generated by username and password, the REST authentication service must be used sending username and password each time the token is required to consume the SW smarter services.For reasons of efficiency and speed of your application or system, it is preferable to use the expireless token instead of generating the token by username and password for each e-invoice that you send to stamp. However, both token generation methods are completely valid and will depend on the particular implementation situation that has to be solved for the choice of one or the other.

Updated on julio 29, 2020

Was this article helpful?