What am I doing wrong while using SerpApi with Connect that results in an api_key error?

This topic was automatically generated from Slack. You can find the original thread here.

I am trying to use the SerpApi with Connect and I am not sure what I am doing wrong. My system is working with out ApiKey type integrations. I have connected and got an account id. Here is an example payload

parameters {
  q: 'site:[leagueofcomicgeeks.com](http://leagueofcomicgeeks.com) "DCeased DC Compact Comics Edition TP"',
  device: 'desktop',
  engine: 'google',
  serpapi: { authProvisionId: 'apn_nphLxB0' }
}

and the error message I am getting

 {
                                        "os": [
                                            {
                                                "k": "error",
                                                "ts": 1748968716630,
                                                "err": {
                                                    "name": "TypeError",
                                                    "stack": "TypeError: Cannot read properties of undefined (reading 'api_key')\n    at Object._makeRequest (file:///tmp/__pdg__/dist/code/3432f7e7d2e22b10dc0662327153121de1ba94ff88baf8bdf1873c213c1e0d24/code/serpapi.app.mjs:47:31)\n    at Object.scrapeSearch (file:///tmp/__pdg__/dist/code/3432f7e7d2e22b10dc0662327153121de1ba94ff88baf8bdf1873c213c1e0d24/code/serpapi.app.mjs:52:19)\n    at Object.run (file:///tmp/__pdg__/dist/code/3432f7e7d2e22b10dc0662327153121de1ba94ff88baf8bdf1873c213c1e0d24/code/actions/scrape-search/scrape-search.mjs:37:37)\n    at file:///var/task/component_maker.mjs:151:42\n    at captureObservations (/var/task/node_modules/@lambda-v2/component-runtime/src/captureObservations.js:28:11)\n    at run (file:///var/task/component_maker.mjs:141:26)\n    at MessagePort.<anonymous> (file:///var/task/component_maker.mjs:177:15)",
                                                    "message": "Cannot read properties of undefined (reading 'api_key')"
                                                }
                                            }
                                        ]
                                    }

Seems likely related to this Pre-built tools for your app or agent — Pipedream

I tried that. Here was the response from getting the configurable props
“result”: [
{
“app”: “serpapi”,
“name”: “app”,
“type”: “app”
},
{
“name”: “engine”,
“type”: “string”,
“label”: “Engine”,
“description”: “Engine to send the query to”
},
{
“name”: “q”,
“type”: “string”,
“label”: “Query”,
“description”: “The query you want to search. You can use anything that you would use in a regular Google search. e.g. inurl:, site:, intitle:. SerpApi also supports advanced search query parameters such as as_dt and as_eq. See the full list of supported advanced search query parameters.”
},
{
“name”: “device”,
“type”: “string”,
“label”: “Device”,
“description”: “Defines the device to use to get the results”
},
{
“name”: “noCache”,
“type”: “boolean”,
“label”: “No Cache”,
“description”: “Force SerpApi to fetch the Google results even if a cached version is already present”
}
],

Can you share the payload for runAction?

{
  actionId: 'serpapi-scrape-search',
  configuredProps: {
    q: 'site:[leagueofcomicgeeks.com](http://leagueofcomicgeeks.com) DCeased DC Compact Comics Edition TP',
    engine: 'google',
    serpapi: { authProvisionId: 'apn_nphLxB0' }
  },
  externalUserId: 'org_CxaZLosyhaBFGWjDeDRQR'
}

A quick scan looks correct, can you try it out here and let me know if it works for you?

It does seem to work there. I am trying to observe the difference in payloads in the network tab but I cant see any differences

Another common error: Pre-built tools for your app or agent — Pipedream

None of the parameters are marked as dynamic though

{
                                            "app": "serpapi",
                                            "name": "app",
                                            "type": "app"
                                        },
                                        {
                                            "name": "engine",
                                            "type": "string",
                                            "label": "Engine",
                                            "description": "Engine to send the query to"
                                        },
                                        {
                                            "name": "q",
                                            "type": "string",
                                            "label": "Query",
                                            "description": "The query you want to search. You can use anything that you would use in a regular Google search. e.g. `inurl:`, `site:`, `intitle:`. SerpApi also supports advanced search query parameters such as `as_dt` and `as_eq`. See the [full list](https://serpapi.com/advanced-google-query-parameters) of supported advanced search query parameters."
                                        },
                                        {
                                            "name": "device",
                                            "type": "string",
                                            "label": "Device",
                                            "description": "Defines the device to use to get the results"
                                        },
                                        {
                                            "name": "noCache",
                                            "type": "boolean",
                                            "label": "No Cache",
                                            "description": "Force SerpApi to fetch the Google results even if a cached version is already present"
                                        }

Though in your demo it has select options for the parameters which means maybe they are indeed dynamic?

Is it possible the account you’ve connected on your end has a bad API key?

I just regenerated the key and got the same error

Hm, can you share the payload you’re seeing from the demo app?

ah, i found it. The appSlug is app instead of serpapi

Ah, astute observation

{ "app": { "authProvisionId": "apn_oOhWyW9" }, "q": "batman" }

This is a bug correct?

That’s not a bug, no, that’s the name of the app prop in the definition you shared, I just missed it there also. It is definitely an inconsistency that we’re working to improve, but it’s not a bug.

yeah this part of the api has a ton of footguns in it. You should really just have a separate param for authProvisionId instead of this magic configurable param in my opinion

When you say a separate parm for authProvisionId, do you mean just not require the app prop in configuredProps?