• Resolved LABCAT

    (@labcat)


    Hi there,

    I am perhaps using your plugin for a different purpose than intended however looking through your code I think it can serve the purpose I want it to as well.

    I am using your Airpress classes to update existing records in an Airtable base when their related records on a WordPress site are updated. This is working very well.

    Now I also want to create a record in Airtable when a new record is created in WordPress (or an existing WordPress record is update that doesn’t already exist in Airtable). For example I have something similar to the following code which I think should work:

    
     $new_post[ 'fields' ] = ['post_title' => 'test', 'post_type' = 'page'];
    $record = new AirpressRecord( $new_post, $collection );
    

    However I get the following error in the debug log:
    “INVALID_REQUEST_UNKNOWN”,”message”:”Invalid request: parameter validation failed. Check your request data.”

    Perhaps I am doing something incorrectly, do you have any examples for how to create Airtable records?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Phillip Dodson

    (@phillip-dodson)

    After digging around the source files, I found this static method that creates records:

    
    $air_data = array(
      'Some Column' => 'Your data',
      'Another Column' => 'More data',
    );
    AirpressConnect::create( 'YOURCONFIG', 'YOURTABLE', $air_data );
    
    Phillip Dodson

    (@phillip-dodson)

    Upon further review, the following seems to be the intended way to add records (that uses the AirpressConnect::create() method from above). The benefit of this method is you actually get a record object of the newly created record.

    
    $record_data = array(
      'Some Column' => 'Your data',
      'Another Column' => 'More data',
    );
    
    $query = new AirpressQuery( 'YOURTABLE', 'YOURCONFIG' );
    $collection = new AirpressCollection( $query, false );
    $new_record = $collection->createRecord( $record_data );
    
    Thread Starter LABCAT

    (@labcat)

    Great thanks for the Phillip, I have got it working well now.

    Thank you very much for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating records in Airpress via API’ is closed to new replies.