This document describes the example applications provided with the AmazonDRS library.
The example:
- authenticates the device on Amazon platform using the provided Client ID and Client Secret
- executes the following cycle: places an order, waits for 8 sec, cancels the order, waits for 12 sec
- logs all responses received from the Amazon DRS
Source code: Replenish.agent.nut
Login to Amazon Developer Services. If you are not registered as a developer, create a developer's account.
- Set up a device
- In the Electric Imp's IDE create new Product and Development Device Group.
- Assign the device to the newly created Device Group.
- Copy the Replenish example source code and paste it into the IDE as the agent code.
- Make a note of the agent's URL. It will be required for the next steps.
- Leave impCentral open in your browser — you will be returning to it later.
This stage is used to authenticate the imp application in Amazon.
- Launch your Amazon Developer Console.
- Click on the APPS & SERVICES tab, then click Login with Amazon.
- Click Create a New Security Profile.
- Enter the following information:
- Security Profile Name:
example_sp
- Security Profile Description:
example_sp_desc
- Consent Privacy Notice URL:
https://example.com
- Security Profile Name:
- Click Save.
- Then you'll be taken to your list of security profiles. Click the gear next to the Security Profile you created and select Security Profile.
- Make a note of your Client ID and Client Secret.
- Then click on the Web Settings tab and enter the agent's URL into the Allowed Return URLs field.
- Click Save.
- Do not close this page.
Note: any LWA Security Profile works only for the one agent the URL of which you entered in the Allowed Return URLs field.
- In the Amazon Developer Console, click the APPS & SERVICES tab and choose Dash Replenishment Service.
- Click the CREATE A DEVICE button.
- In the appeared window, fill in the fields:
- Click Save.
- Open the Slot Localization tab and make a note of Slot ID.
- Return to impCentral.
- Find the AMAZON DRS CONSTANTS section at the end of the agent code, and enter the Client ID, Client Secret and Slot ID from the steps above as the values of the AMAZON_DRS_CLIENT_ID, AMAZON_DRS_CLIENT_SECRET and AMAZON_DRS_SLOT_ID constants, respectively.
- Again, do not close impCentral.
- Click Build & Run All to syntax-check, compile and deploy the code.
- On the log pane, you should see Log in please message. This example uses OAuth 2.0 for authentication, and the agent has been set up as a web server to handle the authentication procedure.
- Make sure there are no errors in the logs.
- Make sure there are periodic logs like this:
- Your application is now up and running.
- You may check that the value of the My_Timestamp__c field in the received event is equal to the value in the sent event.