È possibile utilizzare l'API di Commerce Portal per ottenere informazioni su utenti, contratti, ordini di fatturazione mensili (MBO) e accordi con i Cloud Services Provider. Per interagire con l'API di Commerce Portal, generare un token API in Commerce Portal e scambiarlo con un bearer token.
Per ulteriori informazioni sulle operazioni che è possibile eseguire utilizzando l'API di Commerce Portal, fare riferimento alla documentazione dell'API dell'aggregatore di Commerce Portal.
Come generare un token API
In qualità di utente Amministratore è possibile genere un token API nelle impostazioni del proprio profilo.
Sulla barra degli strumenti di Commerce Portal espandere il menu a discesa accanto al proprio nome utente e fare clic su Profilo.
Per generare un token API, fare clic su GENERA TOKEN.
Selezionare la data di scadenza del token e fare clic su GENERA TOKEN.
Copiare o salvare il token generato e fare clic su CONTINUA.
Come scambiare un token API con un bearer token
Per poter creare richieste autorizzate all'API di Commerce Portal, è necessario scambiare il token API con un bearer token.
Chiamare l'API di autenticazione e scambiare il token API con un bearer token.
curl https://vcp.vmware.com/api/commerce/v1/auth \ -H 'Content-Type:application/json' \ -d '{"type":"UserToken","userToken":"yourAPIToken"}'
La risposta restituisce il bearer token nel parametro "accessToken"
.
{ "tokenType":"bearer", "accessToken":"eyJhbGciOiJIUzUxMiJ9. eyJhdWQiOiJTRVNTSU9OIiwiY29udGV4dCI6IjZmYWExZDM2LTE2NTUtNGY4Ny04ZWE3LWU0NGI0ZTM1MzQ2\ MSIsImlhdCI6MTY1NDgzODc2NSwiZXhwIjoxNjU0ODQwNTY1fQ. W9UCFRPNLpJK1JHKiBSODdjdyRqSBhq6jq7y5JkccmV5Gsw34zXrwiZcFECmhorvk5XW4Ow-1e0zGSR_if8AEQ", "expiresIn":1800 }
Come utilizzare il bearer token nelle richieste API successive
Dopo aver ottenuto il bearer token, impostarlo come intestazione "Authorization"
HTTP per autorizzare le richieste API successive. Il formato corretto da utilizzare è "Authorization: Bearer your_accessToken"
.
L'esempio seguente mostra come viene utilizzato un bearer token in una richiesta GET.
curl https://vcp.vmware.com/api/aggregator/v1/contracts \ -H "Accept: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJTRVNTSU9OIiwiY29udGV4dCI6IjZmYWExZDM2LTE2NTUtNGY4Ny04ZWE3LWU0NGI0ZTM1MzQ2MSIsImlhdCI6MTY1NDgzODc2NSwiZXhwIjoxNjU0ODQwNTY1fQ.W9UCFRPNLpJK1JHKiBSODdjdyRqSBhq6jq7y5JkccmV5Gsw34zXrwiZcFECmhorvk5XW4Ow-1e0zGSR_if8AEQ"