I need to send the following POST request with JavaScript (preferably with fetch() method since I am most familiar with it):
POST /login?format={format} HTTP/1.1
Host: authservice.priaid.ch
Authorization: Bearer {api_key}:{hashed_credentials}
I know the api_key
and took care of the hashed_credentials
part already. (Here is more documentation on this API in case you need it.) I just need to send the fetch request, but don’t know how (I am very new to APIs).
I tried doing the following:
fetch('authservice.priaid.ch/login?format=json', {
method: 'POST',
headers: {
Authorization: `Bearer {my_api_key}:{computedHashString}`,
},
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error));
but it returns an error:
POST http://127.0.0.1:5500/authservice.priaid.ch/login?format=json 405 (Method Not Allowed)