0

I need to send a request to a restful api from Supabase postgreSQL database using http_post function, sending an urlencoded form in body.

I found no specific documentation on supabase: https://supabase.com/docs/guides/database/extensions/http

My specific need is to send this request using supabase http_post extension, to get an access token from microsoft (in Curl to show the parameters I need to encode as x-www-form-urlencoded:

curl --location 'https://login.microsoftonline.com/<my tentant id>/oauth2/v2.0/token'\
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<my app client id>' \
--data-urlencode 'scope=api://<my scope>/.default' \
--data-urlencode 'client_secret=<my client Id secret' \
--data-urlencode 'grant_type=client_credentials'

1 Answer 1

0

I found no specific examples, but after further testing I managed to send an url encoded form using http post and get a valid response from the rest api POST:

select status, ("content"::jsonb)
 from
 http_post('https://login.microsoftonline.com/<my tenantid>/oauth2/v2.0/token',
 '{ "client_id": "<my clientId>", "grant_type": "client_credentials", "client_secret": 
 "<my client app secret>","scope":"api://<my scope>/.default" }'::jsonb
 );

Response:

[
 {
  "status": 200,
  "content": {
  "expires_in": 3599,
  "token_type": "Bearer",
  "access_token": "<token>",
  "ext_expires_in": 3599
 }
} 
]

The above example works with any POST request that requires an urlencoded form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.