PHP SDK - API Call fails to create MX record (SDK bug?)


#1

I have scoured the internet for an answer to this, and found a few examples but no one has had their question answered (that I’ve seen anyway):

Here is my api call:
$zoneID = “e9168fc43618892571b03042c720d019”;
$dns->addRecord($zoneID, “MX”, “@”, “ASPMX.L.GOOGLE.COM”, 1200, false, 10)

I get the following error from the API call:
[message:protected] => Client error: POST https://api.cloudflare.com/client/v4/zones/e9168fc43618892571b03042c720d019/dns_records resulted in a 400 Bad Request response: {“success”:false,“errors”:[{“code”:1004,“message”:“DNS Validation Error”,“error_chain”:[{“code”:9104,“message”:"priority (truncated…)

This error boggles my mind, because the error code (9104) doesn’t seem to apply to my situation so it seems the error code is wrong. The error is also truncated by the lob response which makes it more difficult to debug as well. Can anyone see anything wrong with my code which might cause this response.

NOTE: I do not believe this is an error with the API itself, as I tried a direct curl request with the data sent manually and it works fine. It’s only the PHP SDK which appears to choke on the command. So either the SDK is buggy (??) or something else is happening which I’m not understanding.

PLEASE HELP. Thanks so much.


#2

Hi. I know this is an old thread, but nothing resolved this issue for me. Here is my API attempt:
$dns->addRecord($zoneID, “MX”, “@”, “ASPMX.L.GOOGLE.COM”, 300, false, 10)

and here is the response:
[message:protected] => Client error: POST https://api.cloudflare.com/client/v4/zones/e9168fc43618892571b03042c720d019/dns_records resulted in a 400 Bad Request response: {“success”:false,“errors”:[{“code”:1004,“message”:“DNS Validation Error”,“error_chain”:[{“code”:9104,“message”:"priority (truncated…)

PLEASE HELP?! What am I doing wrong?


#3

The error message appears to be truncated but referring to the priority value. That value seems to be somewhat in a pickle right now, as even the mobile UI doesnt handle it properly right now.

Generally I’d say you pass the right value in the right format as integer. Hence I am a bit surprised you get that error. The interesting bit is PHP’s type hint is a string even though it then casts it to an integer only 15 lines onwards.

I’d probably play with var_dumps around https://github.com/cloudflare/cloudflare-php/blob/cca073c8094a3caa944b3a475fe5226d6a92da14/src/Adapter/Guzzle.php#L48 to figure out what’s actually sent over the wire.


#4

Hi Sandro,

After playing/struggling this for another 3 or 4 hours, in desperation I tried upgrading the SDK version to 1.1.2 (I was on v1.1 before). This FIXED the problem. Go figure…