Make REST-Based Calls With An API Key

Make REST-Based Calls With An API Key

This article provides the resources to support the task of making REST-based calls with an API Key.

 

  1. Use The API Key
    1. Example HTTP Request
    2. Example PowerShell Request With Invoke-WebRequest
    3. Example PowerShell Request With Invoke-RestMethod
    4. Example cUrl Request Example PowerShell Request
    5. Example Response

Use The API Key

The following are examples of using the API key.

The caller passes the API key in the Authorization header like a bearer token.

Example HTTP Request

POST /application HTTP/1.1

Content-Type: application/json

Authorization: Bearer YourApiKeyHere

Host: api.YourSubDomain.fuuz.app

Content-Length: 111

 

{"query":"query {\n\tcurrentUser {\n\t\tuser {\n\t\t\temail\n\t\t}\n\t\ttenant {\n\t\t\tname\n\t\t}\n\t}\n}\n"}

Example PowerShell Request With Invoke-WebRequest

$headers=@{}

$headers.Add("Content-Type", "application/json")

$headers.Add("Authorization", "Bearer YourApiKeyHere")

$response = Invoke-WebRequest -Uri 'https://api.YourSubDomain.fuuz.app/application' -Method POST -Headers $headers -ContentType 'application/json' -Body '{"query":"query {\n\tcurrentUser {\n\t\tuser {\n\t\t\temail\n\t\t}\n\t\ttenant {\n\t\t\tname\n\t\t}\n\t}\n}\n"}'

Write $response

Example PowerShell Request With Invoke-RestMethod

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"

$headers.Add("Authorization", "Bearer YourApiKeyHere")

$headers.Add("Content-Type", "application/json")

 

$body = @"

{`"query`":`"query {`\n`\tcurrentUser {`\n`\t`\tuser {`\n`\t`\t`\temail`\n`\t`\t}`\n`\t`\ttenant {`\n`\t`\t`\tname`\n`\t`\t}`\n`\t}`\n}`\n`"}

"@

 

$response = Invoke-RestMethod 'https://api.YourSubDomain.fuuz.app/application' -Method 'POST' -Headers $headers -Body $body

$response | ConvertTo-Json

Example cUrl Request Example PowerShell Request

 When using a Windows command terminal, it may be necessary to escape the double quotes and avoid single quotes, as is done in this example, which includes Windows-style command continuation with carets.

curl.exe https://api.YourSubDomain.fuuz.app/application ^

 -H "Authorization: Bearer YourApiKeyHere" ^

 -H "Content-Type: application/json" -d "{\"query\":\"query{  currentUser { user { email } }}\"}" -v

Example Response

{

     "data": {

          "currentUser": {

              "user": {

                   "email": "no-reply@domain.com

              },

              "tenant": {

                   "name": "Tenant Name

              }

          }

     }

}