neatnik/omg.lol

[Bug] API - DNS - Edit an existing DNS record does not work as described

ejstreet opened this issue · 4 comments

Bug Description

When trying to update an existing record, a new one is created instead.

The request appears to ignore the record ID when passed. Any and no value can be passed at the end of the URL when using the PATCH method and a new record will be created as long as it is different to an existing record.

Steps to Reproduce

Create a DNS record:

curl --location --request POST --header "Authorization: Bearer $OMGLOL_API_KEY" 'https://api.omg.lol/address/elliott/dns' --data '{"type": "CNAME", "name": "foo", "data": "example.com"}'
{
    "request": {
        "status_code": 200,
        "success": true
    },
    "response": {
        "message": "Your DNS record was created successfully.",
        "data_sent": {
            "type": "CNAME",
            "priority": null,
            "ttl": null,
            "name": "foo.elliott",
            "content": "example.com"
        },
        "response_received": {
            "data": {
                "id": 41905981,
                "name": "foo.elliott",
                "content": "example.com",
                "ttl": 3600,
                "priority": null,
                "type": "CNAME",
                "created_at": "2023-02-05T05:50:43Z",
                "updated_at": "2023-02-05T05:50:43Z"
            }
        }
    }

Attempt to update the record using patch and the ID:

curl --location --request PATCH --header "Authorization: Bearer $OMGLOL_API_KEY" 'https://api.omg.lol/address/elliott/dns/41905546' --data '{"type": "CNAME", "name": "bar", "data": "example.com"}'
{
    "request": {
        "status_code": 200,
        "success": true
    },
    "response": {
        "message": "Your DNS record was created successfully.",
        "data_sent": {
            "type": "CNAME",
            "priority": null,
            "ttl": null,
            "name": "bar.elliott",
            "content": "example.com"
        },
        "response_received": {
            "data": {
                "id": 41905782,
                "name": "bar.elliott",
                "content": "example.com",
                "ttl": 3600,
                "priority": null,
                "type": "CNAME",
                "created_at": "2023-02-05T05:46:12Z",
                "updated_at": "2023-02-05T05:46:12Z"
            }
        }
    }
}

Note that the message is "Your DNS record was created successfully.", and the record has a different id. See that 2 records are now present either by GETing the DNS records or checking in the dashboard.

I think this issue could probably be part of #532, however that issue didn't mention this specific behaviour.

@ejstreet Hey I had this problem too but using some guesswork I workaround it. Basically for this particular API you need specify the id inside the body.

curl --location --request PATCH --header "Authorization: Bearer $OMGLOL_API_KEY" 'https://api.omg.lol/address/elliott/dns/41905546' --data '{"type": "CNAME", "name": "bar", "data": "example.com", **"id":"123456"**}'

Indeed this is weird and I'm not sure if it's by design. Behavior has been inconsistent in different apis but I do understand. Adam got many stuff on his plate :).

btw this issue #534 is related. We can track it there.

@wayneyaoo is correct, and I apologize for the inconsistencies here. Some of these endpoints are a bit of a mess, and I do need to invest the time in doing an overhaul and general tightening of things with an aim toward consistency and accuracy. Hopefully won’t be too much longer before I get to that.

Thanks @newbold, I appreciate the effort.