Reputation: 1
I am wanting to create a firebase hosting site via the firebase Hosting API, I have tested the API in the google docs and this all works creating the requested site.
I have then used the get sites list API via code and this gives me a 200 response with the list of sites in the data.
When I use the post method to create a site I get a 401 response, I have tried a few things, such as including an Empty SITE in the request body, but that gives me a 400 error instead.
I am posting to the following URL:
https://www.googleapis.com/auth/firebase.hosting/projects/my project ID/sites?siteId=idOfNewSite
I have the following defined as the scope:
https://www.googleapis.com/auth/firebase.hosting
Which is the same as used for the get request.
and include the token in the request header as in:
headers: {
Authorization: `Bearer ${token}`
}
I was expecting to get a 200 response with the newly created site details in the Response but instead I just get the 401 error and no other information as to what is wrong.
I tried creating a new API key but that made no difference the get call to
https://www.googleapis.com/auth/firebase.hosting/projects/my project id/sites
works with either key but the post call does not.
Any help / ideas on what I am missing doing wrong would be appreciated.
Upvotes: 0
Views: 89
Reputation: 1
I found the solution, as always it is the little things that matter:
When posting to the URL I just needed to add an empty object as in
const result = await axios.post(`https://firebasehosting.googleapis.com/v1beta1/projects/<<my project ID>>/sites?siteId=idOfNewSite`, {}, {
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
},
},
Upvotes: 0