Call a service with your key
The Call a service task calls another service's API with your secret key and gives your page a short answer. Use it for a search, a stock or price lookup, a listing or anything a service answers, without the key ever reaching the browser.
On this page
- What it does
- Add the task
- Keys to add
- Service address (SERVICE_URL), a setting
- Service key (SERVICE_KEY), a secret
- Fit it to your service
- Connect your page
- Try it in the preview
- Go live
- Services it works with
- Common problems
- The page gets not_set_up
- No result right now
- The service didn't answer
- The service's answer was too big
What it doesLink to this section
- It answers
/api/call-serviceon your site. A page calls it with search words, like/api/call-service?q=blue shoes, up to 200 characters. - It calls the service's address with your key, and puts the words in that address's
qpart. - It gives the page a short copy of the answer: up to 20 items, each text cut to 500 characters. You can choose which fields the page sees.
- Browsers keep the answer for a minute, so the same search doesn't call the service again at once.
Add the taskLink to this section
In Server tasks (top menu), choose Add a ready-made task, pick Call a service and choose Add task. The setup card lists the two keys below, each with Add key.
Keys to addLink to this section
Add Service address first: the form for Service key then fills in which service the key is for.
Service address (SERVICE_URL), a settingLink to this section
Find the address
In the service's API guide, find the address that answers your question, starting with
https://. Leave out theqpart: the task adds it.Add it
Choose Add key next to Service address, paste it and save.
Service key (SERVICE_KEY), a secretLink to this section
Make a key
In the service's dashboard, usually under API keys or developer settings, make a key with read access only, if the service offers that.
Add it
Choose Add key next to Service key and paste it. Under Which service is it for?, check it shows the host of SERVICE_URL: the part after
https://, up to the next slash.
Fit it to your serviceLink to this section
Most services take the key as a Bearer header and search words in q, which is what the task sends. Open api/call-service.ts in Site code, or ask your AI, to change:
- Where the key goes. If the guide puts the key in another header or in the address, change
serviceRequest(). Pass the key as it is: Xodia puts the real key in on its way to the service. - What the search is called. If the service names it something other than q, change it in
serviceRequest()too. - What the page sees. List the fields in
KEEP, like["name", "price"]. Everything else in the service's answer stays on Xodia.
Connect your pageLink to this section
On the Shop page, add a search box that fetches / api/ call-service?q= with the words, and shows each result's name and price. Show the error words when there is no result.Try it in the previewLink to this section
Turn on server tasks
In the setup card, choose Turn on server tasks if they are off.
Search
Use the search box in the preview with a few words you know the service has.
Check the call
In Project settings, Server tasks, Recent calls, pick Preview. A good call shows status 200 and the service among the services it reached.
Go liveLink to this section
Publish your site. The live copy of the task starts answering on your live address.
Services it works withLink to this section
Any service with an HTTP API that answers JSON and takes an API key works, as written when it takes a Bearer key and q, or after the small change above. We haven't listed services by name here: check the service's API guide for where the key and the search words go.
Common problemsLink to this section
The page gets not_set_upLink to this section
SERVICE_KEY or SERVICE_URL isn't added, or SERVICE_URL isn't a full web address. Check both in Keys and secrets.
No result right nowLink to this section
The service said no. Recent calls shows the service's status and its own reason:
- 401 or 403: the key is wrong, goes in another place, or Which service is it for? doesn't match the host in SERVICE_URL.
- 404: the address is wrong. Check SERVICE_URL against the guide.
- 429: you reached the service's limit. Wait, or let your page keep answers longer.
The service didn't answerLink to this section
It took longer than 10 seconds. Try again; if it keeps happening, check the service's status page.
The service's answer was too bigLink to this section
The answer was over about 200,000 characters. Ask the service for fewer results, often with a limit or page size in the address.