VSC Thunder client create hash

46 Views Asked by At

I'm trying to access the Marvel API at https://gateway.marvel.com/v1/public/. I'm a registered user with public and private keys. However, I'm currently only trying to retrieve a list of characters.

Can you help me identify what might be going wrong?

enter image description here

1

There are 1 best solutions below

0
Fictor On BEST ANSWER

I finally found the solution!

Within Collections, in the specific collection Settings -> Scripts -> Choose file, you can upload a script to run before the call is made.

Here is the code for the script I needed:

var crypto = require('crypto-js')

var ts = Date.now()
var priv = 'MY_API_PRIVATE_KEY'
var pub = 'MY_API_PUBLIC_KEY'
var hash = crypto.MD5(`${ts}${priv}${pub}`).toString(crypto.enc.Hex)

tc.setVar('ts', ts)
tc.setVar('hash', hash)

enter image description here