private/Get-MBSAPIHeader.ps1

function Get-MBSAPIHeader {
    <#
    .SYNOPSIS
    Get API request header with MBS token
     
    .DESCRIPTION
    Calls POST method to https://api.mspbackups.com/api/Provider/Login
     
    .PARAMETER ProfileName
    Profile name
     
    .EXAMPLE
    Get-MBSAPIHeader -ProfileName $ProfileName
     
    .INPUTS
    None
 
    .OUTPUTS
    System.Management.Automation.PSCustomObject
 
    .NOTES
        Author: Alex Volkov
    .LINK
 
    #>

    
    [CmdletBinding()]
    param (
        #
        [Parameter(Mandatory=$false, HelpMessage="The profile name, which must be unique.")]
        [string]
        $ProfileName
    )
    
    begin {
        
    }
    
    process {

        if ($ProfileName){
            $APICredLocal = Get-Content "$env:USERPROFILE\.mbs\$ProfileName.json" | ConvertFrom-Json | Select UserName,@{Name="Password";Expression={ConvertTo-SecureString $_.Password}}
            $APICredLocal = New-Object System.Management.Automation.PSCredential -ArgumentList @($APICredLocal.UserName, $APICredLocal.Password)
            #Select Username,@{Name="Password";Expression={ConvertTo-SecureString $_.Password}}
            
        }else{
            $APICredLocal = $APICred
        }

        $BodyProviderLogin = @{
            UserName = $APICredLocal.GetNetworkCredential().UserName
            Password = $APICredLocal.GetNetworkCredential().Password
        }
        $Login = Invoke-RestMethod -Method 'Post' -Uri (Get-MBSApiUrl).ProviderLogin -Body $BodyProviderLogin
        $headers = @{
            'Authorization' = "Bearer " + $Login.access_token
            'Accept' = "application/json"
        }
        return $headers
    }
    
    end {
        
    }
}