Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Performing HTTP Requests w/ Authorization #19

Copy link
Copy link
@4lch4

Description

@4lch4
Issue body actions

Overview

I wanted to create a repo that would use the flat action to store some data from the Twitter API. The problem is the Twitter API requires authorization in order to get any data. With the current version of the flat action (v2.0.2) there's no way to do this.

I created a fork of this repo that can do just that and published it to the marketplace. I wanted to submit a PR but wasn't sure if y'all would actually want to add it the way I did it so I figured I'd share what I did and leave it up to y'all.

Below is an explanation of my solution, and here is a link to my repo where I use the action I created:

4lch4/flat-bot

My Solution

What I did to enable authorization was add a field to the actions with field called Authorization. The value of this field is then passed in as an Authorization header.

The following code snippets are the changes I made to the existing code, there's only three files I changed (aside from the README):

const response = await axios.get(config.http_url, {
  method: 'get',
  responseType: 'stream',
  headers: {
    Authorization: config.Authorization,
  },
})
const HTTPConfigSchema = z
  .object({
    http_url: z.string(),
    Authorization: z.string().optional(),
  })
  .merge(CommonConfigSchema)
// ...
const keys = [
  'downloaded_filename',
  'http_url',
  'Authorization',
  'sql_connstring',
  'sql_queryfile',
  'postprocess',
]
Authorization:
  description: 'A string to send as a header for authorizing API requests.'
  required: false

Links

Current Flat Action Release
My Fork
My Published Action
My Example Usage

mattrothenberg, narphorium, linux-china and michaeloboyle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.