How to assign vertex color to vertex color shader node? Hello I just recently learn about scripting in blender and I have problem attaching materials using script. 

This is my code so far :

face = bpy.data.objects[nama]
face.scale =(0.00001,0.00001,0.00001)
face.rotation_euler.x = pi/2
face.location.z = 3.23

face.material.new(name = 'Skin')
bpy.data.materials["Skin"].node_tree.nodes["Vertex Color"].layer_name = "skin"


I try to copy the script from info when I do it via GUI and fail to do it on script.

The results that I want is like this, where the Base color change from default value into vertex color and select Col and then if possible named it into skin



Lemon's answer is almost correct but it has red label on vertex color and it makes my end result become dark
face.material.new(name = 'Skin')



'face' has no material property. And as the material is new, there is no vertex color in its node tree (and no node tree as it is).

You can:

mat = bpy.data.materials.new(name = "Skin")
mat.use_nodes = True #Make so it has a node tree

#Add the vertex color node
vc = mat.node_tree.nodes.new('ShaderNodeVertexColor')
#Assign its layer
vc.layer_name = "skin"


Now to link the vertex color output to the default principled shader:

#Get the shader
bsdf = mat.node_tree.nodes["Principled BSDF"]
#Link the vertex color to the shader
mat.node_tree.links.new( vc.outputs[0], bsdf.inputs[0] )


Additionnaly, if you want to add it to the 'face' object:

face.data.materials.append(mat)