Code Monkey home page Code Monkey logo

Comments (4)

daveajones avatar daveajones commented on July 2, 2024

Thank you for reporting. Can you email me your API key so I can check the logs: [email protected]

from docs-api.

daveajones avatar daveajones commented on July 2, 2024

Here's the triggering code:
image

Something is keeping the query parameter from coming through.

from docs-api.

zettadam avatar zettadam commented on July 2, 2024

Hmm... but querystring is supplied according to docs?

https://api.podcastindex.org/api/1.0/search/byterm?q=javascript

from docs-api.

zettadam avatar zettadam commented on July 2, 2024

Got it fixed. Thanks @daveajones for helping me identify it.

The issue had to do with the fact that I was generating request headers on server startup and not for each separate request, as it should have been. 'X-Auth-Date' and 'Authorization' headers are time sensitive and have to regenerated for every request.

Here's updated code (I created a function to generate headers which I'm using in each request):

const generateHeaders = () => {
  const ts = Math.floor(Date.now() / 1000)
  const authString = `${API_KEY}${API_SECRET}${ts.toString()}`
  const authHeader = crypto.createHash('sha1').update(authString).digest('hex')

  return {
    'Content-Type': 'application/json',
    'User-Agent' : "AdamZ's homemade podcast-fetcher 0.01a",
    'X-Auth-Key': API_KEY,
    'X-Auth-Date': ts,
    'Authorization': authHeader
  }
}

server.post('/search/term', async (req, res, next) => {
  const headers = generateHeaders()
  const { term } = req.body
  const url = `${API_BASE_URL}search/byterm?q=${term}`

  try {
    const results = await fetch(url, { headers })
    const data = await results.json()
    res.json({
      message: `Podcasts by term: ${term}`,
      data
    })
  } catch (err) {
    next(err)
  }
})

from docs-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.