How to map data from external API

Hello Team,

So I am working on my database where I need to call extrenal API and get contact enrichment I was able to connect to the extrnal API and was able to receive a code:200 but now the issue is I cant map it back to my database as the HTTP Module is not shown in the next modules how can this be fixed ?

Here is the attached

Hello Team,

So I figured out the issue, I had to run the Python script to fix the issue but how ever I am able to receive the data in my python script but I am not able to print it any help here would be appreciated.

Hey,

when you assign variables with Python in the Run Script action, they automatically become output parameters! For example, if your script does:

import httpx
url = 'https://api.exchangerate-api.com/v4/latest/USD'
r = httpx.get(url)
data = r.json()

You’ll see both ‘url’ and ‘data’ values in the Run Script action’s output:

The print() function doesn’t return values though, so you won’t see those in run history.

Run script action docs: Run Script | Bika.ai

Hello Kelvin,

I am able to get the output from the script that I am running but the ouput is not delimated as json output which is not mapable in the next stage what is the solution to this issue ?

This is the code:
import httpx
import json

Define the endpoint and parameters

linkedin_url = “<%= _triggers.trg7rsIZEEtorEwbneVEetIF.record.cells.flds8yb94LbJnAeb9NcUDaZ3.value %>”
api_url = “https://contacts.muraena.ai/api/client_api/reveal/
params = {
“linkedin_url”: linkedin_url
}

Set headers

headers = {
“Authorization”: “Token xxxxxx”,
“Accept”: “application/json”
}

response = httpx.get(api_url, headers=headers, params=params)
data = response.json()

Here is the output:

Let me know how this issue can be resolved.

Best,

Hi Burhan,
Hmm, not sure I fully get what you mean by “not delimited as JSON output” – the screenshot shows your Run Script output is already a JSON object, and the HTTP response looks properly formatted too.

Maybe check how you’re accessing the data in the next step? Here’s a quick demo of using script output values downstream:

insert-variable

Hope this helps!

Hello Kelvin,

I have done exactly the same but cant see the data here is the screenshot. This is the main issue.

Could you head back to the Run Script Action editor and click “Run Test” again? Wait for the HTTP response to show up, then close that editor. Now reopen your Update Record editor and check if the data variable pops up in the variable picker?

The variable list automatically updates based on the latest “Run Test” results from each action, so sometimes we gotta give it another click when stuff changes. Let me know if that works!

Hello Kelvin,

Yes by runing the test run it worked and data is populated, I was actually running the whole automation again even for testing. Anyhow thankyou so much for your support but I need it again as I am stuck in the next step now to map the data with the record.

So the current senario is Trigger > Script > update record. When the automation reaches update record it actually just pulls the current data in the row and wont update the data pulled from the script command. Need your support to map the data correctly unique identifier will be the linkedin link. Here is the screenshot in how I have set it up.

Your support is much appreciated.

Best,

From your “Update Record Action” setup, it looks like it’s only updating the first record in your “Canada Sales Contact” database.

I think you want to use the LinkedIn link to find and update the specific record where linkedin_link matches the one from your Script/Trigger, right?

Quick fix: Add a “Get Record” action before the “Update Record” step. Set its filter to {Canada_Sales_Contact.linkedin_link} = {Script.linkedin_link}. Then in your “Update Record” action, use the Record ID from this “Get Record” output as the target record. Just make sure only one record matches that LinkedIn link, otherwise the automation might get stuck.

This post has a similar setup example: Cant remove header from the list I have! - #8 by Kelvin

Hello Kelvin,

I tried this and it still wont work here is the screenshot

I request connecting with you and fix this issue as its more than a week now I am stuck at this stage appreciate your help but please let us finalize this ASAP.

really sorry you’re still stuck on this! :pray: Since this comunity is meant for sharing knowledge, I can’t offer one-on-one connection here.
Could you help me help you faster? If you could record a quick video (maybe using something like Vimeo) showing your screen while walking me through the error - especially the Run History results and your Find Record Action configuration - that’d be super helpful. The more details you can share, the better chance we have to figure this out together!

Hi sorry if that’s a little off-topic here, but I’m trying to figure out how to perform complex checks on the received data with Python. My example here is that the Send HTTP Request Node received some JSON data. But trying to import that into the Python script node fails with error 500:
What I need is just to check the if the word “check” is seen anywhere in the data. First I tried that more straightforward way:

Hi sorry if that’s a little off-topic here, but I’m trying to figure out how to perform complex checks on the received data with Python. My example here is that the HTTP Request Node received some JSON data. But trying to import that into the Python script node fails with error 500:
What I need is just to check the if the word “check” is seen anywhere in the data. First I tried that more straightforward way:

str0="check"
nostroy="<%= JSON.stringify(_actions.actpDNscAT1IoBoQMeACTvDO.body) %>"
if str0 in nostroy:
  data = "yes"
else:
  data = "no"

But it doesn’t like the way I’m trying to import the data and falls with 500. Then I tried this way but also no luck:

import json
str0="check"
nostroy=json.loads("<%= JSON.stringify(_actions.actpDNscAT1IoBoQMeACTvDO.body) %>")
text_nostroy = json.dumps(nostroy, indent=4)
if str0 in nostroy:
  data = "yes"
else:
  data = "no"

Then I tried to mimick the snippet in this thread (with the manual definition of the inn variable which is a search term):

import httpx
import json
api_url = "https://reestr.nopriz.ru/api/sro/all/member/list"
inn = "4205402325"
headers = {
“Accept”: “application/json”
}
params = {
  "page": 1,
  "sortBy": {},
  "filters": {},
  "pageCount": "100",
  "searchString": inn
}
headers = {}
response = httpx.get(api_url, headers=headers, params=params)
data = response.json()

It still ends with error 500.
So my questions are: is there any restriction on what data can be imported into variables? How can we actually debug - like at least have some error description of why Python has failed? What would be the correct way to perform the following logic:

  1. We receive a value from the trigger which is written to variable inn
  2. We make a request to the API here https://reestr.nopriz.ru/api/sro/all/member/list/
    no headers needed, and the parameters are as follows:
    params = {
    “page”: 1,
    “sortBy”: {},
    “filters”: {},
    “pageCount”: “100”,
    “searchString”: inn
    }
  3. We receive the data with this structure:

    So there are TWO entries (body>data>data>0 and body>data>data>1)
  4. For each entry we must check the following:
    Is the member_status>code = 1? if NO, then skip the entry. If yes, then does the registration_number of this entry have “2010” in it? If yes then output something if no then skip. Same checks for the second entry. I appreciate any help guys :heart_eyes:

P.S. this output is from the Send HTTP Request node, it works well but I need to somehow transfer and parse this data with conditional logic into python node

Hi, I still have a problem here.
I have a Get HTTP Response nodes for two virtually identical APIs.

The node works well if I just change the URL and leave all parameters same:

So, two APIs are on these addresses:
https://reestr.nopriz.ru/api/sro/all/member/list
https://reestr.nostroy.ru/api/sro/all/member/list

I managed to get the first one working with a Python snippet below:

import json 
import httpx

api_url = 'https://reestr.nopriz.ru/api/sro/all/member/list'

headers = {
"Content-Type": "application/json"
}
params = {
  "page": 1,
  "sortBy": {},
  "filters": {},
  "pageCount": "100",
  "searchString": "9702064435"
}
json_params = json.dumps(params)
response = httpx.post(api_url, headers=headers, data=json_params)
data = response.json()

But if I change the URL to the second one it suddenly falls down with error 500.

Where can I check the reason for that? Any idea how to fix?
Again, HTTP Request Nodes work perfectly

Hi, just wanted to update that I managed to get it rolling through trial and error :smiley:

Hi @anp, glad to hear you got it running! :tada:

From the error it looks like a 500 on the server side, so likely not your code. How did you end up fixing it? Anything you think we should improve on our side?

As far as I understand, the Python node ends up with an error 500 every time the python code fails for whatever reason. But there is no way to check what’s the python error so no clear way to debug the code. In my particular case I still haven’t found the reason of the failing. My workaround is that one request is made via Python node and another one is via HTTP Request node, that’s it.

What to improve - I think the python console output atleast when Run Test is mandatory so we can debug effectively. Now it just shows error 500 which means that the node failed somewhere while running the code

@anp, thanks a lot for sharing the details. I’ve passed this feedback along to the product team for review. Really appreciate you taking the time to share such thoughtful input — it helps us keep improving Bika.