1

I am trying to create a fetch request to access this API from Donorbox. Documentation:

https://github.com/donorbox/donorbox-api

I have successfully created this cURL request (redacted info):

curl -X GET --user login@email.com:YOUR_API_KEY https://donorbox.org/api/v1/campaigns

How should the credentials be included in a fetch request in a node file? I've tried including them in an Authorization header:

        const result = await fetch ('https://donorbox.org/api/v1/campaigns', {
            headers: {
                'Authorization': 'Basic ' + btoa('login@email.com:YOUR_API_KEY ')
            }
        })
        console.log(result)
    } catch (error) {
        console.log('ERROR')
        console.log(error)
    }

but node does not recognize btoa(). My other attempts without dtoa() have resulted in error 401.

nizoom
  • 105
  • 6
  • What's `dtoa()`? Did you mean [btoa()](https://developer.mozilla.org/en-US/docs/Web/API/btoa)? – Phil Dec 01 '21 at 00:46

1 Answers1

1

First of all, you can see what headers CURL sends to server by adding --verbose flag.

Secondly, you can convert your string to base64 encoding using function btoa.

Maksym Shcherban
  • 742
  • 4
  • 13