Insert url into an attachment field using sleiman/airtable-php

Hi, I’m using sleiman/airtable-php to integrate airtable with my website, the problem that I’m having right now is inserting a public url where my image is hosted to the attachment field of the table; this is the code:

$url = "<url-of-the-image>";

$attachment = array('url' => $url);
$update_details = array(
    "ID Verification" => $attachment,
);

$update = $airtable->updateContent("Applications/$record_id", $update_details);

And I get this error:

[error] => stdClass Object
    (
        [type] => INVALID_ATTACHMENT_OBJECT
        [message] => Invalid attachment object for field ID Verification: "<url-of-the-image>"
    )

I have also tried to make the $attachment variable an object like this:

$attachment = (object) [ 'url' => $url ];

Or do I have to define $attachment differently or ‘sleiman/airtable-php’ doesn’t support attachment fields?

Help!

1 Like

I think so. If you look at your base structure in airtable.com/api you’ll see the attachment field has different properties, including a URL property, which is probably where you want to write the URL to.

1 Like

Was able to find the answer after searching a little bit more, I needed to add the $attachment variable in one more array:

$url = "<url-of-the-image>";

$attachment = array('url' => "$url");
$update_details = array(
    "ID Verification" => [$attachment],
);

$update = $airtable->updateContent("Applications/$record_id", $update_details);

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.