Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

php - ovh 400 Bad Request response

I am getting this error when trying to create subdomain using ovh API in laravel code.

POST https://eu.api.ovh.com/1.0/domain/zone/mondomain.com/record resulted in a 400 Bad Request response: {"message":"Invalid signature","httpCode":"400 Bad Request","errorCode":"INVALID_SIGNATURE"}

My PHP code looks like :

$ovh = new Api(
    $applicationKey, // Application Key
    $applicationSecret, // Application Secret
    'ovh-eu', // Endpoint of API OVH Europe (List of available endpoints)
    $consumerKey
); // Consumer Key

$result = $ovh->post(
    '/domain/zone/mondomain.com/record',
    array(
        'fieldType' => 'A', // Resource record Name (type: zone.NamedResolutionFieldTypeEnum)
        'subDomain' => 'test-sousdomain', // Resource record subdomain (type: string)
        'target' => 'monIP', // Resource record target (type: string) ssh root@
        'ttl' => '0', // Resource record ttl (type: long)
    )
);
return $result;

Thank for your help.

question from:https://stackoverflow.com/questions/66061092/ovh-400-bad-request-response

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The INVALID_SIGNATURE means some parameters are missing or are some values are not matching the requested parameters type (string, long etc.)

In your case, the parameters ttl needs to be a long, but you gave it a string.

It should be better with:

$result = $ovh->post('/domain/zone/mondomain.com/record', array(
    'fieldType' => 'A', // Resource record Name (type: zone.NamedResolutionFieldTypeEnum)
    'subDomain' => 'test-sousdomain', // Resource record subdomain (type: string)
    'target' => 'monIP', // Resource record target (type: string) ssh root@
    'ttl' => 0, // Resource record ttl (type: long)
));

The only difference here is the '0' vs 0 (without the simple quotes)

The signature can be found here: https://api.ovh.com/console/#/domain/zone/%7BzoneName%7D/record#POST

If you execute your request through this API console, in the Raw tab you can see the generated request:

{
  "fieldType": "A",
  "subDomain": "test-sousdomain",
  "target": "monIp",
  "ttl": 0
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...