Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 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 Answer

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...