Hi Everyone,
I am new to Figma, I am trying to make a plugin that can copy the components from the team-published components to another team’s project.
I have published a few test components in team projects and was able to access the team components list and individual components from Figma API
Now the challenge is how I can create an instance of that component and append it to my current Figma page
Below is the function that can describe my use case
const getComponentDataFromComponentKey = async () => {
const personalAccessToken = ' [ PERSONAL ACCESS TOKEN ]';
const componentKey = ' [ COMPONENT KEY ] ';
const headers = {
'X-Figma-Token': personalAccessToken,
};
const componentSet = await fetch(`https://api.figma.com/v1/components/${componentKey}`, {
method: 'GET',
headers: headers,
});
const componentData = await componentSet.json();
console.log(componentData?.meta);
//Below is something I want to achieve
const componentSetNode = await figma.importComponentByKeyAsync(componentKey);
const instance = componentSetNode.createInstance();
instance.x += 100;
instance.y += 100;
figma.currentPage.appendChild(instance);
};
importComponentByKeyAsync is giving me error 403 error and from componentData?.meta I can’t create the component instance.
Is there any way to do this?
Would be really helpful for your valuable input .
Thanks