I need to call an external API to add a product on another system. For this call I need to attach a security token as an Authoization header to the POST HTTP Request (together with another Header Request information like Content-Type ...).

My code looks like this:

create or replace function AddProductAPI ("JsonLoad" long varchar)

returns long varchar

url 'http://localhost/api/v1/product'

type 'http:post:application/json'

Header 'Content-Type: application/json';-- line5

create or replace procedure AddProduct()


call AddProductAPI ('{"Product_Name": "Mouse","ProductID": "123"}');--*line9


In Web Service I can make use of the function HTTP_HEADER in order to fetch the Header information being passed to me as a Web service/server, but how I can set such header information when I am consuming an external services?

I tried to do it on line5 above! (something like):

Header 'Content-Type: application/json, Authorization' + select @MyToken; -- Syntax Error

When I try to do this using SA_SET_HTTP_HEADER(), on the line before line9, then there is no any syntax error, but also no any effect (it does nothing)!

Any ideas please!

asked 03 Apr, 08:11

Baron's gravatar image

accept rate: 37%

edited 03 Apr, 09:50

Volker%20Barth's gravatar image

Volker Barth

The system procedure sa_set_http_header() is meant for web services, not for web client functions so using the HEADER clause within the CREATE FUNCTION statement is the right appraoch AFAIK. But you cannot add a query result there, instead you can use the substitution parameters (i.e. the "!param" syntax) to provide variable contents to your web client function's definition.

Here's a sample from the docs - I guess it's quite easy to use that as a starting point:

CREATE PROCEDURE test(uid CHAR(128), pwd CHAR(128), headers LONG VARCHAR)
    URL 'http://!uid:!pwd@localhost/myservice'
    HEADER '!headers';
permanent link

answered 03 Apr, 09:49

Volker%20Barth's gravatar image

Volker Barth
accept rate: 34%

Thank you very much.

It was very helpful.

I have another question: How can I issue a PATCH Request? In the documentation is mentioned that there are only 5 types available for http-type-spec-string (so, only GET, POST, PUT, DELETE, HEAD).

If I use this type (PATCH), then I get an error message Invalid Procedure subtype 'PATCH' for type 'HTTP'

(03 Apr, 17:44) Baron
Replies hidden

Well, v17 also lists the OPTIONS method but I guess PATCH simply is not supported then...

But of course you are free to ask to add support for method PATCH as a product suggestion here, because it seems to be used more frequently with REST APIs... Just add it as a separate question with tag product-suggestion or the like...

(04 Apr, 06:37) Volker Barth

what is meant with the OPTIONS method?

I added a product-suggestion!

(04 Apr, 20:10) Baron

The OPTIONS method has been added with v17, see the docs. I guess it's main use is for CORS.

(05 Apr, 08:32) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 03 Apr, 08:11

question was seen: 311 times

last updated: 05 Apr, 08:32