d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
246 stars 101 forks source link

Invoke-D365LcsApiRefreshToken no clientId #496

Closed jfranch closed 3 years ago

jfranch commented 3 years ago

I'm trying to call function Invoke-D365ApiRefreshToken and getting ClientId missing error: image

Previously I asked for a token without issues: image

Maybe I'm missing something?

Splaxi commented 3 years ago

Looking at the help for Set-D365LcsApiConfig

Get-Help Set-D365LcsApiConfig -Full

SYNTAX
    Set-D365LcsApiConfig [[-ProjectId] <Int32>] [[-ClientId] <String>] [[-BearerToken] <String>] [[-ActiveTokenExpiresO
    n] <Int64>] [[-RefreshToken] <String>] [[-LcsApiUri] <String>] [-Temporary] [<CommonParameters>]

So you need to store the ClientId with Set-D365LcsApiConfig, if you don't want to avoid having to specify it.

Note that you're calling Get-D365LcsApiToken with the -ClientId, which explains why it works. But when setting your details with Set-D365LcsApiConfig, you're not providing the -ClientId for the Set-D365LcsApiConfig.

#This will set all parameters that you can avoid specifying again.
Set-D365LcsApiConfig -ClientId -LcsApiUri -ProjectId

#This pulls a fresh token, and stores the BearerToken, RefreshToken and the ActiveTokenExpiresOn values
Get-D365LcsApiToken -Username -Password | Set-D365LcsApiConfig

#This will pull a fresh token, and stores the BearerToken, RefreshToken and the ActiveTokenExpiresOn values
Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig
jfranch commented 3 years ago

Thanks @Splaxi , I didn't found this doc.

Splaxi commented 3 years ago

It might be a bit unclear, if you only look at a single command.

But Get-help will so you everything I have documented.

Splaxi commented 3 years ago

This wiki page shows you some of the same steps.

https://github.com/d365collaborative/d365fo.tools/wiki/How-To-Download-Latest-Bacpac-From-Lcs

jfranch commented 3 years ago

Hi, of course get-help shows a very well structured and plenty documentation. In this case I don't pay attention on optional parameters. The problem is not the documentation.