skip to Main Content

Trying to replace/update type A record name @ using godaddy api in laravel with Guzzle
https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName

Valid Headers

$godaddy = Http::withHeaders([
    'Authorization' => 'sso-key ' . config('godaddy.key') . ':' . config('godaddy.secret'),
]);

I try the get method and it works

$response = $godaddy->get('https://api.godaddy.com/v1/domains/example.com/records/A/@');

Method put

$response = $godaddy->put('https://api.godaddy.com/v1/domains/example.com/records/A/@', [
    'records' => [
        'data' => '127.0.0.1',
        'priority' => 0,
        'ttl' => 0,
        'weight' => 0
    ],
]);

Response details

array:3 [▼
  "code" => "INVALID_BODY"
  "fields" => array:1 [▼
    0 => array:3 [▼
      "code" => "UNEXPECTED_TYPE"
      "message" => "is not a array"
      "path" => "records"
    ]
  ]
  "message" => "Request body doesn't fulfill schema, see details in `fields`"
]

¿What i am doing bad?

Edited:
Try

$records = json_decode('[{"data": "127.0.0.1","name": "@","port": 65535,"priority": 0,"protocol": "string","service": "string","ttl": 0,"type": "A","weight": 0}]');
$response = $godaddy->put('https://api.godaddy.com/v1/domains/example.com/records', [
    'records' => $records,
]);
$response = $godaddy->put('https://api.godaddy.com/v1/domains/example.com/records/A/@', [
    'records' => [
        [
            'data' => '127.0.0.1',
            'priority' => 0,
            'ttl' => 0,
            'weight' => 0
        ]
    ],
]);

2

Answers


  1. I’m guessing records is supposed to be an array of arraysobjects:

    $response = $godaddy->put('https://api.godaddy.com/v1/domains/example.com/records/A/@', [
        'records' => [
            [
                'data' => '127.0.0.1',
                'priority' => 0,
                'ttl' => 0,
                'weight' => 0
            ]
        ],
    ]);
    
    
    Login or Signup to reply.
  2. I think you need to work with array of objects. You need to encoding with right way.

    $result = [
                [
                  "data" => "string",
                  "port"  => 65535,
                  "priority" => 0,
                  "protocol" => "string",
                  "service" => "string",
                  "ttl" => 0,
                  "weight"  => 0
                ]
            ];
    
            $records = json_encode($result);
    
    $response = $godaddy->put('https://api.godaddy.com/v1/domains/example.com/records/A/@', [
        'records' => $records,
    ]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search