Api integration to use forms

Aloha,

Situation:

We have a client side js application that’s using our own api for a variety of functions. The client application is expected to display a form (which is created in Hubspot) and allow users to submit this form. The submission will be sent to our own api, which in turn will submit the form to Hubspot api. So, our api will integrate with Hubspot (not the client app).

So far:

To ensure that I could render the Hubspot form in the client application, I used an api key to pull the form meta data from hubspot into our api. Our client app calls our api to get this information and renders it without any issues. My next step is to remove the api token and use OAuth instead, for both retrieving the form metadata and submitting it. I only used the api key for a quick POC of rendering the form.

OAuth integration issue

I’ve read through your documentation, but I’m not sure how to integrate api to api, keeping in mind that we’re not dealing with a user that’s using a browser; it’s api to api.

1. I created an application as per your instructions

2. I copied the full url into the browser and executed it

3. I approved access to one of my accounts

4. I observed the code parameter value that you appended to the url when redirecting

5. I tried to use the following url to get a token:

POST https://api.hubapi.com/oauth/v1/token

As payload I tried:

{ "grant_type" : "<code appended to redirect>", "client_id" : "<client id from app config page>", "client_secret" : "<client secret from app config page>", "redirect_uri" : "<exact uri as entered on app config page>", "code" : "<code appended to redirect>" }

as well as

grant_type=authorization_code&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&client_secret=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy&redirect_uri=https://www.example.com/&code=zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz

with content type set as per your help page.

I get the following result:

POST https://api.hubapi.com/oauth/v1/token

HTTP/1.1 500 Internal Server Error
Date: Thu, 30 Sep 2021 15:52:37 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 100
Connection: keep-alive
CF-Ray: 696e9e8f5cfaf4d0-HNL
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Vary: Accept-Encoding
CF-Cache-Status: DYNAMIC
Access-Control-Allow-Credentials: false
Expect-CT: max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct
X-HubSpot-Correlation-Id: 2e404d6d-bce5-43f8-9b04-ce199ddd80ec
X-Trace: 2B66D3D9692F2A2AA06AAB2100F9D07D0FFFD24629000000000000000000
Report-To: {“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=<token removed>”}],“group”:“cf-nel”,“max_age”:604800}
NEL: {“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}
Server: cloudflare
alt-svc: h3=“:443”; ma=86400, h3-29=“:443”; ma=86400, h3-28=“:443”; ma=86400, h3-27=“:443”; ma=86400

{
“status”: “error”,
“message”: “internal error”,
“correlationId”: “2e404d6d-bce5-43f8-9b04-ce199ddd80ec”
}

Response code: 500 (Internal Server Error); Time: 238ms; Content length: 100 bytes

@cinsulan ,

Try changing the value for grant_type to authorization_code

There is a chance you may need to disconnect your test portal and reconnect to get a new code

I just tested on my end. Please see screengrab from postman

Thanks!

So, I created a new app and got it to work.

1. Create app and give it scope etc

2. Use browser to validate the app (just make sure you’re saved and no warning at the top)

3. When validating, grab the code=xxxxxxxx-xx-xx-xxx from the console (this is the only tricky part)

4. Configure Api call as follows:

POST https://api.hubapi.com/oauth/v1/tokenContent-Type: application/x-www-form-urlencodedgrant_type=authorization_code&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&client_secret=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&redirect_uri=https://urltoyoursite&code=xxxxxx-xxxx-xxxx-xxxxx