This article describes how to add a new API user in the Nexus Push Service to get a unique API key to use. 

Prerequisites

  • Nexus Push Service installed, see here.

Step-by-step instruction

  1. Navigate to the top-level directory where docker-compose.yml is located. The config file should then be found in a config/ directory.

    mydir/
    |-- cacerts
    |-- certificates
    |-- config
    |   |-- application.yml -> cod-nps.yml
    |   `-- cod-nps.yml
    `-- docker-compose.yml


  2. Open the configuration file for editing:

    vi config/cod-nps.yml


  3. Open a browser and go to the following URL, using a unique <myclientid>:

    http://localhost:20200/<contextPath>/<uriBase>/util/generateclient/<myclientid>


    All requests below are triggered from the host itself, thus localhost is used.

    Please note that the port number might have been assigned a different value. To find out the current port number, type:

    docker ps | grep nps_nps


  4. Copy the content from the resulting web page and paste it into the allowedClients section of the configuration file.

          # X-Api-Key: a2Fyb2xpbjpmZDA0ZGUyZjFlNTU0NGIyOTE1ZEJhNjUwOThjNDkwNjM3YTA3MTVmNWM5ODQzNDU5ZjA1ZGZjMjk4MzQyOTM2 
          - clientId: <myclientid> 
            key: fd04de2f1e5544b2915d1a65098c490637a0715f5c9843459f05dfc298342936 
    


    Make sure not to add extra spaces in the configuration file, since the .yml file format is space sensitive.


  5. Save and exit the configuration file.


  1. Refresh the configuration:

    curl -X POST http://localhost:20200/<contextPath>/refresh


  2. Test the new key by sending a request using curl (set THE-NEW-KEY below):

    curl -w%{http_code} -X POST \
      https://nps.nexusgroup.com/notification/push \
      -H 'cache-control: no-cache' \
      -H 'content-type: application/json' \
      -H 'x-api-key: THE-NEW-KEY' \
      -d '{
     "pushId""api-test",
     "title""This is a test",
     "body""This is a test"
    }'


  3. Check the response.
    1. If you get a 403 response, you have the wrong API key.
    2. If you get this response or similar, then you have the correct API key:


      {"result":{"status":"ERROR"}}404

      This response means that the pushId is wrong, which is expected at this point.  


Related information