deko bobos
deko bobos

Reputation: 11

OVH API Error: This call has not been granted

I need to use OVH API in my Python code but the call returns this error:

OVH API Error: This call has not been granted

import json                                                          
import ovh

client = ovh.Client(
    endpoint='ovh-eu',
    application_key='application_key',                                              
    application_secret='application_secret',                                
    consumer_key='consumer_key',                          
)


project_id = 'project_id '                            

try:
    result = client.get(
        '/cloud/project/' + project_id + '/image',                    
        flavorType=None,
        osType=None,
        region='SBG5'
    )
    print(json.dumps(result, indent=4))
    
except ovh.APIError as e:
    print(f"OVH API Error: {str(e)}")
    print(f"OVH Query ID: {e.response.headers.get('X-Ovh-Queryid')}")

return this :

(venv) PS C:\Users\user\Desktop\pythonFiles\Ovh> python step1_list_services.py

OVH API Error: This call has not been granted

OVH-Query-ID: EU.ext-3.655b414a.69585.e84e84691cd2e05baa9eec9585016b18

OVH Query ID: EU.ext-3.655b414a.69585.e84e84691cd2e05baa9eec9585016b18

Upvotes: 0

Views: 1342

Answers (1)

Pierre
Pierre

Reputation: 2752

You have this error because the API call you're trying (GET /cloud/project/{project_id}/image) is not granted for the token you generated.

When you generate a token, you need to specify for which API path and HTTP verb (GET, POST etc) this token needs to be granted.

You can specify which API path/HTTP verb needs to be granted in two different ways:

$ curl -X POST \
     -H "X-Ovh-Application: <application_key>" \
     -H "Content-type: application/json" \
     https://eu.api.ovh.com/1.0/auth/credential \
     -d '{
            "accessRules": [
                {
                    "method": "GET",
                    "path": "/cloud*"
                },
                {
                    "method": "POST",
                    "path": "/cloud*"
                },
            ],
            "redirection": "https://ovhcloud.com/"
        }'

You will find the complete documentation about API here.

Upvotes: 1

Related Questions