|
| 1 | +# How to get your App token |
| 2 | + |
| 3 | +Implement the required parts of the App activation process and receive an App access token for querying your PIM API. |
| 4 | + |
| 5 | +<table class="tag-container"> |
| 6 | + <tr> |
| 7 | + <td>Use case:</td> |
| 8 | + <td> |
| 9 | + <button aria-pressed="false" class="tag-selectable"> |
| 10 | + <div class="tag-color tag-color-light-blue"></div> |
| 11 | + <div class="tag-label">App Workflow</div> |
| 12 | + </button> |
| 13 | + </td> |
| 14 | + </tr> |
| 15 | +</table> |
| 16 | + |
| 17 | +## What you will learn |
| 18 | +In this tutorial, we provide a guide on how to implement the required parts of your App for the activation process based on OAuth 2.0 with Authorization Code. |
| 19 | +At the end of this tutorial, your App will receive an Access Token and will be able to call the REST API of a PXM Studio. |
| 20 | + |
| 21 | +::: warning |
| 22 | +Examples in this tutorial use languages without any framework or library and, consequently, don't follow all the recommended best practices. |
| 23 | +We strongly encourage you to adapt those examples with the framework or library of your choice. |
| 24 | +::: |
| 25 | + |
| 26 | +::: tips |
| 27 | +If you prefer to start with a fonctionnal App (in PHP), have a look [here](/apps/app-developer-tools.html) |
| 28 | +::: |
| 29 | + |
| 30 | +## Step 1: Expose your activation and callback URLs |
| 31 | + |
| 32 | +First, your application must expose an **activation URL**. |
| 33 | + |
| 34 | +In our example, we won't do additional steps (like authentification), so we will launch the Authorization Request immediately in this Activation URL. |
| 35 | + |
| 36 | +!!!include(content/apps/create-app/activate-php.md)!!! |
| 37 | +!!!include(content/apps/create-app/activate-nodejs.md)!!! |
| 38 | +!!!include(content/apps/create-app/activate-python.md)!!! |
| 39 | +!!!include(content/apps/create-app/activate-java.md)!!! |
| 40 | + |
| 41 | +Then, your application must expose a **callback URL**. |
| 42 | + |
| 43 | +!!!include(content/apps/create-app/callback-php.md)!!! |
| 44 | +!!!include(content/apps/create-app/callback-nodejs.md)!!! |
| 45 | +!!!include(content/apps/create-app/callback-python.md)!!! |
| 46 | +!!!include(content/apps/create-app/callback-java.md)!!! |
| 47 | + |
| 48 | + |
| 49 | +::: info |
| 50 | +You can find more information about the authorization process and code challenge in the following documentation. |
| 51 | +- [OAuth Authorization and authentication](/apps/authentication-and-authorization.html#) |
| 52 | +::: |
| 53 | + |
| 54 | +## Step 2: Get a public URL for your in development App |
| 55 | + |
| 56 | +::: info |
| 57 | +if you use a local version of PIM, skip this step |
| 58 | +::: |
| 59 | + |
| 60 | +Before proceeding to step 4 create a test App in your developer sandbox, you will need valid URLs to your App. This can be easily resolved with a tunnel to your localhost. |
| 61 | + |
| 62 | +There are several ways to create a tunnel to your localhost such as **localhost.run** or **ngrok**. We will use [localhost.run](https://localhost.run/) for its free and easy setup. |
| 63 | + |
| 64 | +### Initiate localhost tunnel |
| 65 | + |
| 66 | +Initiate localhost tunnel using the following command: |
| 67 | + |
| 68 | +```shell |
| 69 | + |
| 70 | +ssh -R 80:localhost:8080 localhost.run |
| 71 | +``` |
| 72 | + |
| 73 | +The command above assumes that your local App is available on port 8080 but you can specify any port you want. |
| 74 | + |
| 75 | + |
| 76 | +### Extract URL from the output |
| 77 | + |
| 78 | +If everything goes well the command will output your public URL for your local app: |
| 79 | + |
| 80 | +```shell |
| 81 | + |
| 82 | +46672a93dd64.lhrtunnel.link tunneled with tls termination, https://46672a93dd64.lhrtunnel.link |
| 83 | +``` |
| 84 | + |
| 85 | +Your local app is now available at `https://46672a93dd64.lhrtunnel.link`. You may now use it for your development. |
| 86 | + |
| 87 | +## Step 3: Get your test app credentials |
| 88 | + |
| 89 | +To get credentials for your app, you need to create a test app on your developer sandbox. |
| 90 | + |
| 91 | +First of all, go to `Connect`, then `App Store` |
| 92 | + |
| 93 | +### Permissions |
| 94 | + |
| 95 | +If you see `Create a test App` skip to [Connect app](https://www.notion.so/Guided-tutorial-How-to-get-your-app-token-022acb1113c1413faefaec3c8f3585a5), else please enable the `developer mode`. |
| 96 | + |
| 97 | + |
| 98 | +To do so, you need to: |
| 99 | +1. Go to `System`, then `Roles` |
| 100 | +2. Choose the role you use for your user |
| 101 | +3. In the `Permissions` tab, scroll down and search for the `Developer mode` submenu |
| 102 | +4. Select `Manage test apps` |
| 103 | +5. Don't forget to save your modifications |
| 104 | + |
| 105 | +### Connect app |
| 106 | + |
| 107 | +To create a test App: |
| 108 | +1. On the top right corner, click on `Create a test App` |
| 109 | +2. Fill in all the required information |
| 110 | +  |
| 111 | +3. Then click on `Create` |
| 112 | +4. Copy/paste credentials in your app configuration file |
| 113 | +  |
| 114 | +5. And click on `Done` |
| 115 | +6. Your test App appears on the App Store page |
| 116 | + |
| 117 | + |
| 118 | +## Step 4: Connect your test App and access its settings |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +Connecting a test App is like connecting a published App. |
| 123 | + |
| 124 | +1. Launch your APP |
| 125 | +2. Click on `Connect` |
| 126 | +3. Your App opens in a new tab of your browser |
| 127 | +4. Launch the connection process from your App |
| 128 | +5. Follow all the activation process steps, then `Confirm` |
| 129 | +6. Your test App is now connected with Akeneo PIM! 🔗 |
| 130 | + |
| 131 | +Now that your App is connected, you can enjoy all the available App features from the Akeneo PXM Studio UI and test that your App works well. |
| 132 | + |
| 133 | +To access the settings of your connected App on Akeneo PIM, please go to `Connected Apps`, then click on `Manage App`. |
| 134 | +You can also open your App from Akeneo PIM UI, to do so, click on `Open app`. |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +::: info |
| 139 | +To know more about the step-by-step activation process, please read our article: |
| 140 | +[How to connect an App?](https://help.akeneo.com/pim/serenity/articles/how-to-connect-my-pim-with-apps.html#how-to-connect-an-app) |
| 141 | +::: |
| 142 | + |
| 143 | +## Step 5: Use your access token to call the API |
| 144 | + |
| 145 | +At the end of this process, you receive the following response with an `access_token`: |
| 146 | + |
| 147 | +```json |
| 148 | + |
| 149 | +{ |
| 150 | + "access_token": "Y2YyYjM1ZjMyMmZlZmE5Yzg0OTNiYjRjZTJjNjk0ZTUxYTE0NWI5Zm", |
| 151 | + "token_type": "bearer", |
| 152 | + "scope": "read_products write_products" |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +You can use this token to call the Akeneo PIM REST API. |
| 157 | + |
| 158 | +<div class="block-next-steps"> |
| 159 | + <img src="../img/illustrations/illus--Attribute.svg" width="140px"> |
| 160 | + <div class="block-next-steps-column"> |
| 161 | + <div class="block-next-steps-title">Next Steps</div> |
| 162 | + <div class="block-next-steps-text">Now that you collected your categories, we advise you to follow</div> |
| 163 | + <div> |
| 164 | + <ul> |
| 165 | + <li><a href="https://api.akeneo.com/apps/overview.html">Learn more about Apps</a></li> |
| 166 | + <li><a href="https://api-staging.akeneo.com/api-reference-index.html">Explore the REST API reference</a></li> |
| 167 | + </ul> |
| 168 | + </div> |
| 169 | + </div> |
| 170 | +</div> |
0 commit comments