cancel
Showing results for 
Search instead for 
Did you mean: 

How to GET API with a base URL that changes?

JoeS
Level 2
Hi,

I am trying to build an object to call an API to get some information about different items. The item names form the base URL, and are not a parameter or header.


URL format:
https://website.api/[ITEM_NAME]/​

Examples:

https://website.api/blue-item/

https://website.api/red-item/

https://website.api/green-item/


I'd like to have a data item in the Blue Prism object or process that can be overwritten to replace [ITEM_NAME] in the URL format. Is this possible? I have been able to do this for parameters and headers after configuring the API (in System > Web API Services), but haven't found a solution for the base URL path changing itself.

Apologies if I have misunderstood something here, thanks.

4 REPLIES 4

PvD_SE
Level 12

Hi Joe,

I am perhaps missing the point, but isn't this as simple as a Calculation stage doing this:

Replace("https://website.api/MyItemName/​", "MyItemName", [Current Item])

...where [Current Item] contains "blue-item" or any of the other varieties?

Or perhaps simply:

Replace([URL], "MyItemName", [Current Item])

...where [URL] contains "https://website.api/MyItemName/​", and [Current Item] contains "blue-item" or any of the other varieties?

Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)

bruce.liu
Staff
Staff
Hi Joe,

For Web API Services feature, you can create Common Parameters, and choose to expose them to processes. When specifying the Base URL, use placceholders enclosed by a pair of square bracket to reference the Common Parameters defined.

In your case, you will have https://website.api/[ITEM_NAME]/​ as Base URL, and then a Common Parameter called ITEM_NAME of type Text exposed to process so you can manipulate as needed by your process.

JoeS
Level 2
Thank you Paul and Bruce for your replies,

@Bruce Liu I can follow your steps okay and made an object that successfully calls the API and gets a response - but only when the [ITEM_NAME] text is entered into the action itself. When I try to use a data item variable in the object to send values into the action stage, I get a HTTP bad request error. I've tried with the data item text in double quotes and without, both produce the HTTP error response.

I'm not sure why this is the case, the data item should just be passing whatever text into the action stage, right? And the action stage itself works. Any advice would be very appreciated.​

bruce.liu
Staff
Staff
Hi Joe,

See below for an example of the use of placeholder of what I meant. I have also attached a BP release with the example for your information. Note that you may not be able to run this in your environment.

36545.png
36546.png
To troubleshoot your request, you can consider enable the following two options in your request. This will expose the full request in the way how Blue Prism will send it but not actually sending it to the host. In your process/object, kindly expose these data items to see the results. In this way, you can inspect how the placeholder you created would impact your web request.

36547.png
Hope this helps.