exportclassNasaPicsimplementsINodeType{description:INodeTypeDescription={// Basic node details will go hereproperties:[// Resources and operations will go here]};}
properties:[{displayName:'Resource',name:'resource',type:'options',noDataExpression:true,options:[{name:'Astronomy Picture of the Day',value:'astronomyPictureOfTheDay',},{name:'Mars Rover Photos',value:'marsRoverPhotos',},],default:'astronomyPictureOfTheDay',},// Operations will go here]
type 控制n8n为资源显示的UI元素类型,并告知n8n预期从用户处获取的数据类型。options会导致n8n添加一个下拉菜单,允许用户选择其中一个选项。更多信息请参阅Node UI elements。
{displayName:'Operation',name:'operation',type:'options',noDataExpression:true,displayOptions:{show:{resource:['astronomyPictureOfTheDay',],},},options:[{name:'Get',value:'get',action:'Get the APOD',description:'Get the Astronomy Picture of the day',routing:{request:{method:'GET',url:'/planetary/apod',},},},],default:'get',},{displayName:'Operation',name:'operation',type:'options',noDataExpression:true,displayOptions:{show:{resource:['marsRoverPhotos',],},},options:[{name:'Get',value:'get',action:'Get Mars Rover photos',description:'Get photos from the Mars Rover',routing:{request:{method:'GET',},},},],default:'get',},{displayName:'Rover name',description:'Choose which Mars Rover to get a photo from',required:true,name:'roverName',type:'options',options:[{name:'Curiosity',value:'curiosity'},{name:'Opportunity',value:'opportunity'},{name:'Perseverance',value:'perseverance'},{name:'Spirit',value:'spirit'},],routing:{request:{url:'=/mars-photos/api/v1/rovers/{{$value}}/photos',},},default:'curiosity',displayOptions:{show:{resource:['marsRoverPhotos',],},},},{displayName:'Date',description:'Earth date',required:true,name:'marsRoverDate',type:'dateTime',default:'',displayOptions:{show:{resource:['marsRoverPhotos',],},},routing:{request:{// You've already set up the URL. qs appends the value of the field as a query stringqs:{earth_date:'={{ new Date($value).toISOString().substr(0,10) }}',},},},},// Optional/additional fields will go here
{displayName:'Additional Fields',name:'additionalFields',type:'collection',default:{},placeholder:'Add Field',displayOptions:{show:{resource:['astronomyPictureOfTheDay',],operation:['get',],},},options:[{displayName:'Date',name:'apodDate',type:'dateTime',default:'',routing:{request:{// You've already set up the URL. qs appends the value of the field as a query stringqs:{date:'={{ new Date($value).toISOString().substr(0,10) }}',},},},},],}
import{IAuthenticateGeneric,ICredentialType,INodeProperties,}from'n8n-workflow';exportclassNasaPicsApiimplementsICredentialType{name='NasaPicsApi';displayName='NASA Pics API';// Uses the link to this tutorial as an example// Replace with your own docs links when building your own nodesdocumentationUrl='https://docs.n8n.io/integrations/creating-nodes/build/declarative-style-node/';properties:INodeProperties[]=[{displayName:'API Key',name:'apiKey',type:'string',default:'',},];authenticate={type:'generic',properties:{qs:{'api_key':'={{$credentials.apiKey}}'}},}asIAuthenticateGeneric;}
{// All node names must start with "n8n-nodes-""name":"n8n-nodes-nasapics","version":"0.1.0","description":"n8n node to call NASA's APOD and Mars Rover Photo services.","keywords":[// This keyword is required for community nodes"n8n-community-node-package"],"license":"MIT","homepage":"https://n8n.io","author":{"name":"Test","email":"test@example.com"},"repository":{"type":"git",// Change the git remote to your own repository// Add the new URL here"url":"git+<your-repo-url>"},"main":"index.js","scripts":{// don't change},"files":["dist"],// Link the credentials and node"n8n":{"n8nNodesApiVersion":1,"credentials":["dist/credentials/NasaPicsApi.credentials.js"],"nodes":["dist/nodes/NasaPics/NasaPics.node.js"]},"devDependencies":{// don't change},"peerDependencies":{// don't change}}