Laravel Lesson Today: Notion API - Authorizing Public Integrations

·

2 min read

Today I learned how to start a Notion API project with Laravel. I learned the Notion API because I wanted to create a side project with the Notion tool.

This blog won't be long, because in exploring the Notion API with Laravel I followed an article by @faridmovsumov:

In this blog, I will only share how I solved the problem when I followed the tutorial.

There are several obstacles:

  1. Notion suggests redirect_uri to be https.

image.png

For this problem, I searched for a solution with the keyword "reading HTTPS on local" I found a good article, but in Indonesian: https://www.iltekcomputer.com/how-to-activate-https-localhost-xampp-in-windows-become-secure/.

  1. The last obstacle, is there is an error when running the script in the article. Where the notion access page has the message "Missing or invalid redirect_uri" as shown below.

image.png

After looking for some references on StackOverflow, I finally found the problem, we have to remove redirect_uri on uri redirect to API, also during post process.

In welcome.blade.php

Error:

<a href="https://api.notion.com/v1/oauth/authorize?owner=user&client_id={{ config('notion.client_id') }}&redirect_uri={{ urlencode(route('getToken')) }}&response_type=code">Add to Notion</a>

Solved with:

<a href="https://api.notion.com/v1/oauth/authorize?client_id={{ config('notion.client_id') }}&response_type=code">
                Add to Note
  </a>

And in AuthController.php

Error:

'form_params' => [
         'grant_type' => 'authorization_code',
         'code' => $code,
         'redirect_uri' => route('getToken'),
 ],

Solved with:

'form_params' => [
         'grant_type' => 'authorization_code',
         'code' => $code,
 ],

Only that. Thanks for reading. :)