You can add an External API Lookup extension to your stack to allow you to fetch resources from third-party/external apps using APIs and display the resources in a field in Contentstack. Using this extension, content managers can select one or more resources from a list of possible values while creating an entry.
This step-by-step guide explains how to create an Extension API Lookup extension for your content types:
- Add the ‘External API Lookup’ Extension to your Stack
- Use your custom field
Step 1 - Add the ‘External API Lookup’ custom field to your stack
- Go to Settings > Extensions. Click on the + Add Extension button on the top-right corner and select Create new.
- Select Custom Field.
- On the configuration page, enter details in the fields as given below:
- Title: Provide a suitable title for your extension field. For example, ‘External API Lookup’.
- Field Data Type: Select the data type in which the input data of the field should be saved in Contentstack. Select ‘Text’ in this case.
- Multiple: Select this checkbox if you want to enable multiple inputs for the field.
- Hosting method: Select ‘Hosted By Contentstack’. As soon as you do this, you will see the ‘Extension Source Code’ field below.
- Extension Source Code: Enter the source code for the extension. You can find the source code for the External API Lookup extension here.
- Config Parameter: Provide values for the config parameters if you have used any in your source code. For the External API Lookup extension, you need to provide the Rest API endpoint that fetches the list. Here’s an example:
Note: You can provide specific instance-level configuration settings for each of the instances of your Custom Field Extension when setting up your content type. The configuration that you provide for an instance will only be applicable for that instance and will not affect any other instances of the same custom field extension or any other fields within the same content type. Learn more.Here's how the configuration page looks like:
- Click on Save. This creates your extension.
Now, let’s understand how you can start using your extension in your content type.
Step 2 - Use your custom field
To use your custom field, you need to follow the steps given below:
- Create a content type by clicking on the + New Content Type. Enter the relevant details for the content type and click on Create and Add fields.
This leads you to the Content Type Builder page where you can add the relevant fields.
- Add the Custom field in your content type.
- Select External API Lookup from the dropdown and set the other properties of your custom field.
Note: You can provide specific instance-level configuration settings for your Custom Field extension. Learn more.
- After adding other relevant fields in your Content Type, click on Save and Close.
This will create your Content Type. Now, go to the content type and create a new entry. Enter the relevant details. In the External API Lookup field, select any value while creating an entry for this content type as shown below: