Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How I can insert a link in a Notion table? #119

Closed
wahibAbdouWbs opened this issue Jun 8, 2021 · 5 comments
Closed

How I can insert a link in a Notion table? #119

wahibAbdouWbs opened this issue Jun 8, 2021 · 5 comments

Comments

@wahibAbdouWbs
Copy link

I tried to insert a text and a link into a Notion table it did work with the text but it didn't with the website link?
this is my express POST route any help?
Screen Shot 2021-06-08 at 17 12 49
Notion Table:
Screen Shot 2021-06-08 at 17 14 19

@yassinebridi
Copy link

URLs can be inserted without content, and without brackets, so just like this:

  Website: { url: req.body.website },

@wahibAbdouWbs
Copy link
Author

Unfortunately didn't work I have no idea why but I will just insert it all as text type. Thanks 🙏

@huuphongnguyen
Copy link

@wahibAbdouWbs Did you got any example code write to Notion Database using Next.js or React? Thank you so much.

@wahibAbdouWbs
Copy link
Author

@wahibAbdouWbs Did you got any example code write to Notion Database using Next.js or React? Thank you so much.

I did develop a separated API backend from my front-end I'm not sure if it is possible to do that directly using notion-sdk-js.

@yassinebridi
Copy link

yassinebridi commented Jun 9, 2021

This is straight from my personal website:
I'm using the Fetch API directly since this library is not playing nice with Next.js
/api/create-contact:

import { createPage, databasesId } from '@lib';
import { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const { Name, Email, Company, Content, Deadline, Brief } = req.body;
  const newContact = await createPage({
    parent: { database_id: databasesId.sections.contact },
    properties: {
      Name: {
        title: [
          {
            text: {
              content: Name,
            },
          },
        ],
      },
      Email: {
        rich_text: [
          {
            text: {
              content: Email,
            },
          },
        ],
      },
      Company: {
        rich_text: [
          {
            text: {
              content: Company,
            },
          },
        ],
      },
      Content: {
        rich_text: [
          {
            text: {
              content: Content,
            },
          },
        ],
      },
      Deadline: {
        select: {
          name: Deadline,
        },
      },
      Brief: { url: Brief },
    },
  });

  return res.status(200).json({
    ok: true,
    data: newContact,
  });
}

And the createPage is defined like this:

const notionBaseApi = 'https://api.notion.com/v1';

const fetchConfig: RequestInit = {
  headers: {
    Authorization: `Bearer ${process.env.NOTION_TOKEN}`,
    'Notion-Version': '2021-05-13',
  },
};

export const createPage = async (
  args: WithAuth<PagesCreateParameters>
): Promise<PagesCreateParameters> => {
  const res = await fetch(`${notionBaseApi}/pages`, {
    ...fetchConfig,
    headers: {
      ...fetchConfig.headers,
      'Content-Type': 'application/json',
    },
    method: 'post',
    body: JSON.stringify(args),
  });
  const data = await res.json();
  return data;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants