Home > Net >  Laravel guzzle http godaddy - UNEXPECTED_TYPE records is not array
Laravel guzzle http godaddy - UNEXPECTED_TYPE records is not array

Time:11-19

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
        ]
    ],
]);

CodePudding user response:

I'm guessing records is supposed to be an array of arrays\objects:

$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
        ]
    ],
]);

CodePudding user response:

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', [
    'records' => $records,
]);
  • Related