0

Using Content Hub v4.2

I would like to fetch the data in Content Hub using the REST API, but couldn't find any Postman related examples.

I tried this to get the token with no luck.

enter image description here

  1. Is it the right API end point?
  2. What should be the client_id. I just used the same name I gave when creating the API key in Content Hub.
  3. Should the API key be Scoped or global?
  4. When giving the username & password of a user, should that user be a superuser?

Here is a link of documentation for old version but the Postman collections seems to no longer exist.

https://doc.sitecore.com/ch/en/developers/30/cloud-dev/rest-api--about.html

And since then any newer version doesn't mention about a Postman collection.

UPDATE:

I have modified the Content-Type and it now says Invalid client_id. I have created a new global API key api_test.

enter image description here

enter image description here

4

2 Answers 2

2

The API endpoint you are using appears to be correct, but there are a few things that could be causing issues with your authentication request:

  1. When requesting a token from the Content Hub API, you should use the /oauth/token endpoint and set the request method to POST. Additionally, the Content-Type header should be set to application/x-www-form-urlencoded. The client_id value should match the API key name you created in Content Hub, and the grant_type value should be set to password. The username and password should be provided in the request body as username and password parameters, respectively.

You can read more in this specification and in Sitecore documentation.

  1. The client_id value should be the client ID of the API key you created in Content Hub. You can find this ID by navigating to the "API Keys" section in Content Hub and clicking on the key you created. The client ID will be listed on this page.

  2. The API key can be either scoped or global, but it needs to have the appropriate permissions to access the resources you are trying to retrieve via the API. Make sure that the API key has the necessary scopes and permissions.

  3. The user whose credentials you are using to authenticate should have the necessary permissions to access the resources you are trying to retrieve via the API. The user does not necessarily need to be a superuser, but they do need to have the appropriate permissions.

Below the CULR that can be imported into Postman for future usage:

curl -X POST -u "{{client_id}}:{{secret}}" \
 http://marketingcontenthub/oauth/token \
 -d grant_type=password -d username={{username}} -d password={{password}}

How to get {{client_id}} and {{secret}}:

  1. Log in to your Content Hub account.
  2. Go to the Admin section.
  3. Click on the OAuth Clients tab.
  4. Click on the Create New button.
  5. Enter a name for the client.
  6. Select the appropriate grant types.
  7. Add the necessary redirect URIs.
  8. Click on the Create button.

You will now see the Client ID and Client Secret for your OAuth client. Then you can set it in Postman Environment variables.

After importing you need to set all variables in Postman accordingly or replace tokens with actual values.

7
  • Are you sure it is /auth/token and not /oauth/token. Because when I change the url to /auth/token, the results says The link you followed may be broken, or the page may have been removed.
    – sukesh
    Mar 10, 2023 at 9:47
  • It was a typo. oauth is a correct one. You are right. Updated an answer Mar 10, 2023 at 10:01
  • I now get the error Invalid client_id But the name is correct. I have updated my question. Could you please check.
    – sukesh
    Mar 10, 2023 at 10:10
  • @Qwerty what API key you have? Is it corresponding to your client_id? Is it global? Mar 10, 2023 at 10:14
  • It's a global API key
    – sukesh
    Mar 10, 2023 at 10:14
0

As per the Sitecore documentation, if you are creating a token using Oauth then you have to pass the following parameters in you request.

  • client_id (required): The unique id for the client application specied when creating the client entity.
  • secret (required): the client secret specied when creating the client entity.
  • username (required): the username of the user to login with.
  • password (required): the password of the user to login with.

And your request should looks like this.

$ curl -X POST -u "client_id:secret" \
 http://marketingcontenthub/oauth/ token \
 -d grant_type=password -d username={username} -d password={password}

Try setting these parameters in your postman request and check.

Refer to this official document for more details.

https://doc.sitecore.com/ch/en/developers/34/cloud-dev/rest-api--create-token-oauth.html

To get the token, you can also use the authenticate API that looks like this.

/api/authenticate

And the body parameters will be user_name and password.

POST /api/authenticate

{
    "user_name":"Username",
    "password":"Password"
}

Document Reference: https://doc.sitecore.com/ch/en/developers/34/cloud-dev/rest-api--get-token.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.