Skip to content
On this page
netzo/apis/medium

Medium

Medium is a place to write, read, and connect. It is easy to find and follow the things that matter to you most on Medium.

  • labels: blogging, writing, publishing, content
  • authentication: bearer

Usage

ts
import { medium } from 'https://deno.land/x/netzo/apis/medium/mod.ts'

const { api } = medium({
  accessToken: Deno.env.get('MEDIUM_ACCESS_TOKEN'),
})
import { medium } from 'https://deno.land/x/netzo/apis/medium/mod.ts'

const { api } = medium({
  accessToken: Deno.env.get('MEDIUM_ACCESS_TOKEN'),
})

Configuration

The medium factory function expects an object with the following, and returns an object with an HTTP client api.

ParamTypeDefaultDescription
accessTokenstringDeno.env.get('MEDIUM_ACCESS_TOKEN')the token to use for authentication

Refer to the API documentation to get the required information.

Examples

The following examples assume you have created an api client instance. Refer to the type definitions for all exported types to pass to the api client for typed responses.

Find publications

Find all publications a user is subscribed to, writes to, or edits.

ts
import type { Publications } from 'netzo/apis/medium/types.ts'

const result = await api.users[USER_ID].publications.get<Publications>()
const resultData = result.data
import type { Publications } from 'netzo/apis/medium/types.ts'

const result = await api.users[USER_ID].publications.get<Publications>()
const resultData = result.data

Get user

Get the authenticated user's info.

ts
import type { User } from 'netzo/apis/medium/types.ts'

const result = await api.me.get<User>()
const resultData = result.data
import type { User } from 'netzo/apis/medium/types.ts'

const result = await api.me.get<User>()
const resultData = result.data

Add post

Create a post to the authenticated user's profile.

ts
import type { DataAddPost, Post } from 'netzo/apis/medium/types.ts'

const data: DataAddPost = {
  title: 'New Post',
  contentFormat: 'html',
  content: '<h1>New title</h1><p>This is new post content</p>'
}
const result = await api.users[AUTHOR_ID].posts.post<Post>(data)
const resultData = result.data
import type { DataAddPost, Post } from 'netzo/apis/medium/types.ts'

const data: DataAddPost = {
  title: 'New Post',
  contentFormat: 'html',
  content: '<h1>New title</h1><p>This is new post content</p>'
}
const result = await api.users[AUTHOR_ID].posts.post<Post>(data)
const resultData = result.data

References