Skip to main content
Question

Defining SearchOrCreate from Search and Create methods in a Resource

  • December 13, 2024
  • 1 reply
  • 17 views

I have a resource with a key of artistResource and a noun of ‘famous painter’.  My resource has a list, search and create operation.  In my main index.js file I would like to have a SearchOrCreate action that leverages the search and create operations from my artistResource resource.  Unfortunately I get a validation error with any combination of references to the resource’s operations.

Error:

== Property
App.searchOrCreates.artistResource
== Message
requires property "search"

== Property
App.searchOrCreates.artistResource
== Message
requires property "create"
== Links


== Property
App.searchOrCreates.artistResource.key
== Message
must match a "key" from a search (options: artistResourceSearch)


== Property
App.searchOrCreates.artistResource.key
== Message
must match a "key" from a create (options: artistResourceCreate)

Version 1 - index.js:

    searchOrCreates: {
      [artistResource.key]: {
      key: artistResource.key,
      display: {
        label: 'Find or Create an artist.',
        description: 'Find or Create Painters',
    },
    search: artistResource.search.key,
    create: artistResource.create.key,
    },

Version 2 - index.js: 

    searchOrCreates: {
      [artistResource.key]: {
      key: artistResource.key,
      display: {
        label: 'Find or Create an artist.',
        description: 'Find or Create Painters',
    },
    search: artistResourceSearch.key,
    create: artistResourceCreate.key,
    },

Partial artistResource.js

module.exports = {
  key: 'artistResource',
  noun: 'famous painter',

  list: {
    display: {
      label: 'Famous Painter',
      description: 'Lists all artists.',
      hidden: true
    },
    operation: {
      perform: performList,
     [...]
    }
  },

  search: {
    display: {
      label: 'Find artist',
      description: 'Finds an artist based on name.',
    },

    operation: {
      inputFields: [
        {
          key: 'name', 
          required: true, 
          helpText: 'Find artist with this name.',
        },
      ],
      sample: {
        name: 'Bob Ross'
      },

      outputFields: [
        { 
          key: 'id', 
          label: 'artist_id'
        },
      ],
      perform: performSearch
    },
  },

  create: {
    display: {
      label: 'Create artist',
      description: 'Create a new artist',
      hidden: false,
    },
    operation: {
      inputFields: [
          {
          key: 'name',
          label: 'Artist Name',
          type: 'string',
          required: true,
          altersDynamicFields: false,
        },

        [...]
      ],
      sample: {'name': 'Bob Ross'},
      outputFields: [{"key": 'artist_id', "type": "integer"},
                      {"key": 'name', "type": "string"},
                    ],
      perform: performCreate, 
    }
  },
};

 

Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30727 replies
  • December 13, 2024

Hi ​@Chipl71 

Is this related the Zapier Developer Platform?

If yes, then make sure to post your topic in the category: Developer Zone

https://community.zapier.com/p/developer-zone