-2

I am using the below code to get Marvel API data:

const axios = require('axios');

const md5 = require('blueimp-md5');
const publickey = 'publickey';
const privatekey = 'privatekey';
const ts = new Date().getTime();
const stringToHash = ts + privatekey + publickey;
const hash = md5(stringToHash);
const baseUrl = 'https://gateway.marvel.com:443/v1/public/characters';
const url = baseUrl + '?ts=' + ts + '&apikey=' + publickey + '&hash=' + hash;

async function getMarvel(){
    const { data } = await axios.get(url);
    return data; 
}

Below is fragment of the output:

{
        "id": 1009150,
        "name": "Agent Zero",
        "description": "",
        "modified": "1969-12-31T19:00:00-0500",
        "thumbnail": {
          "path": "http://i.annihil.us/u/prod/marvel/i/mg/f/60/4c0042121d790",
          "extension": "jpg"
},
  
{
    "id": 1011031,
    "name": "Agent X (Nijo)",
    "description": "Originally a partner of the mind-altering assassin Black Swan, Nijo spied on Deadpool as part of the Swan's plan to exact revenge for Deadpool falsely taking credit for the Swan's assassination of the Four Winds crime family, which included Nijo's brother.",
    "modified": "1969-12-31T19:00:00-0500",
    "thumbnail": {
      "path": "http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available",
      "extension": "jpg"
    },

If I want only Agent Zero from my API call can I do something like this:

const baseUrl = 'https://gateway.marvel.com:443/v1/public/characters?name=Agent+Zero';

This throws a 409 error, what can I change to get only one agent data?

Swayam Shah
  • 200
  • 1
  • 12
  • 2
    If you're looking to just get that from the response that is very easy, but if you're asking how to make it only return that one data point, it's something you'll need to figure out from the APIs documentation. – Zero Nov 04 '21 at 01:22
  • 1
    How is this different to your [previous question](https://stackoverflow.com/questions/69832429/not-able-to-search-for-character-name-in-marvel-api-using-nodejs)? – Phil Nov 04 '21 at 01:27
  • @Phil Do you see any reply on the previous question? Me neither – Swayam Shah Nov 04 '21 at 01:38
  • That doesn't mean _"post a new question"_ – Phil Nov 04 '21 at 01:41
  • I think I explained it better here – Swayam Shah Nov 04 '21 at 01:43

1 Answers1

-1

Was a syntax issue,

This:

const url = baseUrl + '?ts=' + ts + '&apikey=' + publickey + '&hash=' + hash;

Should be:

const url = baseUrl + '&ts=' + ts + '&apikey=' + publickey + '&hash=' + hash;

Replaced question mark with ampersand in ts

Swayam Shah
  • 200
  • 1
  • 12