> For the complete documentation index, see [llms.txt](https://developers.bloomcredit.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.bloomcredit.io/recipes/query-credit-data-using-r.md).

# Query Credit Data using R

Using the Bloom R SDK, authenticate, create consumers and order credit data in R.

## Install the devtools libray

{% code title="R, lines 1-2" %}

```r
install.packages("devtools")
library(devtools)
```

{% endcode %}

devtools lets us pull the latest version of the bloom R library directly from github

## Load the Bloom R library

{% code title="R, lines 4-5" %}

```r
install_github("bloomcredit/BloomR")
library(bloomR)
```

{% endcode %}

Here we are using the previously installed devtools library to install the bloomcredit R library directly from Github.

You can browse the library at the [following link](https://github.com/bloomcredit/bloomR)

## Load credentials

{% code title="R, lines 7-8" %}

```r
client_id <- "<client_id>"
client_secret <- "<client_secret>"
```

{% endcode %}

Replace `<client_id>` and `<client_secret>` with your Bloom API Credentials.

If you don't have client credentials, please [Contact Us](https://bloomcredit.io/contact-us/)

## Fetch an Auth Token

{% code title="R, lines 11-14" %}

```r
auth_token <- fetch_auth_token(
  client_id = client_id,
  client_secret = client_secret
)
```

{% endcode %}

Using the previously created credentials, fetch an auth token for the subsequent calls.

## Create a new consumer

{% code title="R, lines 16-31" %}

```r
consumer_info <- list(
  ssn = "123456789",
  city = "Scranton",
  line1 = "1725 Slough Avenue",
  state_code = "PA",
  zipcode = "18503",
  date_of_birth = "1964-03-15",
  first_name = "Michael",
  last_name = "Scott",
  address_primary = TRUE
)

consumer_id <- register_consumer(
  consumer_info = consumer_info, 
  auth_token = auth_token
)  
```

{% endcode %}

Create new consumer info and register consumer in Bloom. This consumer will be used to query credit data.

## Order Credit Data

{% code title="R, lines 33-38" %}

```r
credit_order <- order_credit_data(
  consumer_id = consumer_id, 
  portfolio_id = "<portfolio_id>", 
  sku = "<sku>",
  auth_token = auth_token
)
```

{% endcode %}

Using the previously created consumer, Order Credit Data. Replace the `<portfolio_id>` with the id of the portfolio you want the consumer to be registered in. Replace the `<sku>` with the chosen sku for the credit data report.

To fetch your available portfolios, see [our API to fetch Organizations](/reference/core/organizations/returns-an-organization.md)

## Fetch Credit Data

{% code title="R, lines 40-43" %}

```r
credit_data <- get_credit_data(
  order_id = credit_order$data$id,
  auth_token = auth_token
)
```

{% endcode %}

Once created, fetch your credit data using the previous order.

## Congratulations!

{% code title="R, lines 1-41" %}

```r
install.packages("devtools")
library(devtools)

install_github("bloomcredit/BloomR")
library(bloomR)

client_id <- "<client_id>"
client_secret <- "<client_secret>"


auth_token <- fetch_auth_token(
  client_id = client_id,
  client_secret = client_secret
)

consumer_info <- list(
  ssn = "123456789",
  city = "Scranton",
  line1 = "1725 Slough Avenue",
  state_code = "PA",
  zipcode = "18503",
  date_of_birth = "1964-03-15",
  first_name = "Michael",
  last_name = "Scott",
  address_primary = TRUE
)

consumer_id <- register_consumer(
  consumer_info = consumer_info, 
  auth_token = auth_token
)  

credit_order <- order_credit_data(
  consumer_id = consumer_id, 
  portfolio_id = "<portfolio_id>", 
  sku = "<sku>",
  auth_token = auth_token
)

credit_data <- get_credit_data(
  order_id = credit_order$data$id,
```

{% endcode %}

credit\_data is now filled with all your consumer credit\_data.

You have completed a R app interacting with the Bloom API and can automate all your credit-data related workflows through this app.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.bloomcredit.io/recipes/query-credit-data-using-r.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
