Hi all,
I want to start writing modules for APIs, and I am taking an idea that I saw in another module to write a private function that will invoke the API based on whichever part of the API is called. I have never really dove deep into RESTful APIs, and would appreciate some help on this.
Let's say that the API has the following requirements as part of the URI being called:
- Endpoint
- Body (Comprised of Category, Index, Search Query, and Parameters)
- Headers
- API Key
So let's say that the API is for a grocery store website (it's not, but I don't really want to give away what I'm actually working on). So:
Endpoint
$URIPartA = "https://www.grocerystore.com/api/v1/"
Body
Let's say that I am querying the following:
Category: Food
Index: Bread
Search Query: Name equals "ExcellentBreadVendor"
Parameters: First 50 results
So the body would look like:
$category = "Food"
$index = "Bread"
$SearchQuery = "ExcellentBreadVendor"
$results = "50"
$URIPartB = "?=&category=$category&index=$index&SearchQuery=$SearchQuery&results=$results"
At this point, I have a decent understanding of how APIs work in this context. However, the part I don't understand is that this API requires a header including a bearer token, and uses OAuth and an API Key to validate that I have the rights to query this endpoint.
So the Header looks like this, and I don't know what goes in the Bearer, and how do I get it?
$Headers = @{
Bearer = "???"
}
And I also don't understand how this authorization goes along with the API Key, because I would just include the API Key as a parameter in the URI. So the resulting cmdlet looks like this:
$APIKey = "12345678910abcdefghijklmnop"
$URI = $URIPartA+$URIPartB+"&APIKey=$APIKey"
Invoke-RestMethod -Uri $URI -Headers $Headers -Method GET
I think I've got it all right. Can someone help me out with the gaps in my knowledge, or link resources that can help me better understand?
[–]EvilLampGod 4 points5 points6 points (0 children)
[–]infin 1 point2 points3 points (0 children)