# Creating a Credit Data Order

After creating a consumer (see [Create Consumer](https://developers.bloomcredit.io/docs/create-your-first-consumer) for reference as how to register a consumer), you can start ordering credit data for that consumer using a **sku** (`sku` name in the request) and a **portfolio** (with `portfolio_id` in the request).

Credit Data can be ordered synchronously (blocking) or asynchronously (non-blocking), and the HTTP request will either return immediately when ordering credit data asynchronously, or the HTTP request will wait until the entire credit data order completes in a terminal state.

Please refer to [Order States](https://developers.bloomcredit.io/docs/ordering-data#order-states) for more information on how the order can be processed.

## Order Credit Data Sample Request

You can see an example of a `POST` request made to the **Order Credit Data** endpoint below:

```curl
curl --location --request POST 'https://sandbox.bloom.dev/v2/data-access/orders/' \
--header 'Authorization: Bearer <ACCESS_TOKEN_WILL_BE_HERE>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
}'
```

```http
POST /v2/data-access/orders/ HTTP/1.1
Host: sandbox.bloom.dev
Authorization: Bearer <ACCESS_TOKEN_WILL_BE_HERE>
Content-Type: application/json
Content-Length: 541

{
   "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
}
```

```javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <ACCESS_TOKEN_WILL_BE_HERE>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://sandbox.bloom.dev/v2/data-access/orders/", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

```python
import requests
import json

url = "https://sandbox.bloom.dev/v2/data-access/orders/"

payload = json.dumps({
  "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
})
headers = {
  'Authorization': 'Bearer <ACCESS_TOKEN_WILL_BE_HERE>',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

```text
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://sandbox.bloom.dev/v2/data-access/orders/',
  'headers': {
    'Authorization': 'Bearer <ACCESS_TOKEN_WILL_BE_HERE>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
  })
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

url := "https://sandbox.bloom.dev/v2/data-access/orders/"
  method := "POST"

payload := strings.NewReader(`{
    "data": {
        "type": "order",
        "attributes": {
            "consumer_id": "<CONSUMER_ID>",
            "portfolio_id": "<ACCOUNT_ID_WILL_BE_HERE>",
            "sku": "equifax-gold-hard-fico"
        }
    }
}`)

client := &http.Client {}
  req, err := http.NewRequest(method, url, payload)

if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Authorization", "Bearer <ACCESS_TOKEN_WILL_BE_HERE>")
  req.Header.Add("Content-Type", "application/json")

res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

## Order Credit Data Sample Response

You can see an example of a response from the **Order Credit Data** endpoint below:

```json
{
    "data": {
        "type": "order",
        "id": "58cb4230-04ce-4915-9d27-d4deb7b603a0",
        "attributes": {
            "status": "PROCESSING"
        }
    }
}
```

### Rejected Order response

```json
{
  "data": {
    "type": "orders",
    "id": "5ebf4d5c-15f8-492d-8f72-b593f80b35cf",
    "attributes": {
      "status_code": "10",
      "status_message": "SKU not enabled",
      "status": "REJECTED"
    }
  }
}
```

### Async Order response

```json
{
  "data": {
    "type": "orders",
    "id": "4d6d92af-ae16-4dac-b028-3c9172e60ddc",
    "attributes": {
      "status": "PROCESSING"
    }
  }
}
```

### Get Success Order response

```json
{
  "data": {
    "type": "orders",
    "id": "4d6d92af-ae16-4dac-b028-3c9172e60ddc",
    "attributes": {
      "consumer_id": "52705fc7-d0ff-47b9-bbfd-5519b706c541",
      "sku": "equifax-bronze-hard",
      "order_placed": "2023-04-17T17:57:21.812057Z",
      "order_filled": "2023-04-17T17:57:21.98094Z",
      "order_updated": "2023-04-17T17:57:21.99703Z",
      "status": "SUCCESS"
    }
  }
}
```

## Possible causes for REJECTED response

### Status code 10: SKU not enabled.

```json
{
    "data": {
        "type": "order",
        "id": "58cb4230-04ce-4915-9d27-d4deb7b603a0",
        "attributes": {
            "status_code": "10",
            "status_message": "SKU not enabled",
            "status": "REJECTED"
        }
    }
}
```

### Status code 11: Invalid consumer id.

```json
{
    "data": {
        "type": "order",
        "id": "58cb4230-04ce-4915-9d27-d4deb7b603a0",
        "attributes": {
            "status_code": "11",
            "status_message": "Invalid consumer id",
            "status": "REJECTED"
        }
    }
}
```

### Status code 12: Invalid portfolio id.

```json
{
    "data": {
        "type": "order",
        "id": "58cb4230-04ce-4915-9d27-d4deb7b603a0",
        "attributes": {
            "status_code": "12",
            "status_message": "Invalid portfolio id",
            "status": "REJECTED"
        }
    }
}
```

### Status code 13: minor.

```json
{
    "data": {
        "type": "order",
        "id": "58cb4230-04ce-4915-9d27-d4deb7b603a0",
        "attributes": {
            "status_code": "13",
            "status_message": "Consumer is minor",
            "status": "REJECTED"
        }
    }
}
```

## Checking order status

After submitting an order for consumer data, you can then check order status by just passing using the order_id that we originally provided to you.

### Get order status sample request

```curl
curl --location --request GET 'https://sandbox.bloom.dev/v2/data-access/orders/<ORDER-ID>' \
--header 'Authorization: Bearer <ACCESS_TOKEN_WILL_BE_HERE>' \
```

### Get order status sample response

You can see an example of the response with the details of the order here:

```json
{
    "data": {
        "type": "order",
        "id": "b097d8cd-f72b-4fbb-aad1-7454e0e8ce82",
        "attributes": {
            "consumer_id": "1f3259d8-f115-4c4b-9bf6-3b704f57b9a7",
            "sku": "",
            "order_placed": "2023-03-16T18:28:42.297018Z",
            "order_filled": "2023-03-16T18:28:42.433244Z",
            "order_updated": "2023-03-16T18:28:42.45531Z",
            "status": "SUCCESS"
        }
    }
}
```
