How to use URL writeback function?

Hi, I’m trying to create a URL writeback function to keep a field updated with the current url of the location pages I have published. I’ve found this example created by the Yext services team - pages-starter-react-consulting/functions/onUrlChange/urlWriteback.ts at main · yextconsulting/pages-starter-react-consulting · GitHub

I’m a little confused on where this plugin should be used. After I update the custom field and API key with the ones specific to my account and apply the plugin using “yext resources apply”, where in the platform should I use it? It can’t be used in a connector because it doesn’t take any data input, and I tried creating a webhook but all the pages related options were disabled.

1 Like

Hi Michael,

We’re actually working on a feature for URL writebacks that will come out soon. If this isn’t urgent, you can wait for the feature instead of using the plugin.

Awesome, that will be very helpful for future sites. I’d like to get the fields for my current site synced ASAP, so if you guys have advice on how to use the URL writeback plugin that would be super helpful!

The function needs to be in the repo of your site rather than CaC applied. In the example link you posted you can see that it’s in a the functions folder of that starter. When you create a deployment of your site where the repo contains that function, it will be auto-registered with the Yext Plugins system. It will only work for the deploy that has been published to production.

1 Like

Thanks, that makes sense. I’ve added the function to my repo and published it to production, but none of the entities got updated. Looking at the app logs it didn’t make any API calls. I’ve given the app Entities (Management API) - Read/Write permission, is there anything else I need to add to get the function to run on a publish?

Function I added:
import { urlWritebackPlugin } from “/mod.ts | yextpages@plugins@1.0.0-beta.3 | Deno”;

const pageUrlCustomField = “landingPageUrl”;
const API_KEY = “I put my API key here”;

// Update field in platform to match actual URL from page
const main = urlWritebackPlugin({
field: pageUrlCustomField,
apiKey: API_KEY,
environment: “prod”,
v: “20221010”,
});

export default main;

There’s a “Trigger Url Change” action on the deploy. Try running that.

I triggered that and also republished and triggered again, but still no update, and the app api logs don’t show anything. If it would be helpful I could give you access to the repo or share some of the account info privately