I create a function in code repo that makes a call to api and creates a 'SearchPeople" object based on the results. I tested the code using livePreview and there is no error, i get the results from api and it seems the objects are being created. Except that when i check Ontology manager there are no 'SearchPeople" objects there, its like its not storing them. I invoked this api via a custom frotnend as well and I dont get any results. What could I being wrong?
import { OntologyEditFunction, Query, ExternalSystems, Edits, Action} from “@foundry/functions-api”;
import { LinkedInAPI } from “@foundry/external-systems/sources”;
import { Objects, SearchPeople } from “@foundry/ontology-api”;
import { Uuid } from “@foundry/functions-utils”;
export class LinkedInFunctions {
@Edits(SearchPeople)
@OntologyEditFunction()
private async callLinkedInWebhook(
category: string,
advanced_keywords: {
title: string,
company: string,
school: string,
},
keywords: string,
api: string,
): Promise<void> {
const apiKey = LinkedInAPI.getSecret("apiKeyValuef2fff0ec10d844cab86eb099ea5bebd2"); // Specify the correct secret name
const baseUrl = LinkedInAPI.getHttpsConnection().url;
const endpoint = '/api/v1/linkedin/search'; // Specify the correct endpoint
const response = await fetch(`${baseUrl}${endpoint}?limit=5&account_id=TKoQkm0IQUuKKz1kw-Nbrg`, {
method: 'POST',
headers: new Headers({
'accept': 'application/json',
'content-type': 'application/json',
'X-API-KEY': apiKey
}),
body: JSON.stringify({
api: api,
category: category,
advanced_keywords: advanced_keywords,
keywords: keywords
})
});
if (response.ok) {
const result = await response.json();
const items = result.items;
let num = 0;
console.log(items)
for (const item of items) {
const searchPeople = Objects.create().searchPeople(Uuid.random());
searchPeople.id = item.id;
searchPeople.name = item.name;
searchPeople.memberUrn = item.member_urn;
searchPeople.publicIdentifier = item.public_identifier;
searchPeople.profileUrl = item.profile_url;
searchPeople.publicProfileUrl = item.public_profile_url;
searchPeople.profilePictureUrl = item.profile_picture_url;
searchPeople.profilePictureUrlLarge = item.profile_picture_url_large;
searchPeople.networkDistance = item.network_distance;
searchPeople.location = item.location;
searchPeople.headline = item.headline;
searchPeople.keywordsMatch = item.keywords_match;
searchPeople.sharedConnectionsCount = item.shared_connection_count ?? "";
if(num === 1){
console.log(`Created SearchPeople object: ${JSON.stringify(searchPeople)}`);
}
num +=1;
}
} else {
throw new Error(`LinkedIn API call failed: ${response.statusText}`);
}
}
@ExternalSystems({ sources: [LinkedInAPI] })
@Query({ apiName: "searchpeople" })
public async searchLinkedIn(
category: string,
advanced_keywords: {
title: string,
company: string,
school: string,
},
keywords: string,
api: string
): Promise<SearchPeople[]> {
await this.callLinkedInWebhook(category, advanced_keywords, keywords, api);
// Query and return the stored SearchPeople objects
// Add a delay
await new Promise(resolve => setTimeout(resolve, 2000));
// Query and return the stored SearchPeople objects
const results = Objects.search().searchPeople().all();
console.log(`Found ${results.length} SearchPeople objects`);
return results;
}
}