# Epicor REST API PowerShell Script Generator

> Source: https://netray.co/tools/epicor-rest-api-powershell-script-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in your server, company and service name to generate a PowerShell script that calls Epicor REST v2 and saves the result to CSV.

## Category

epicor

## Erp

Epicor Kinetic

## Audience

- Epicor developer
- Integration developer
- ERP administrator

## Tool

**Kind:** template

**Output:** code

**Language:** powershell

**Fields:**

#### Server host name

**Key:** server

**Type:** text

**Default:** erp.example.com

#### Instance name

**Key:** instance

**Type:** text

**Default:** KineticLive

#### Company ID

**Key:** company

**Type:** text

**Default:** EPIC06

#### Business object service

**Key:** service

**Type:** text

**Default:** Erp.BO.PartSvc

#### Entity set

**Key:** entity

**Type:** text

**Default:** Parts

#### Fields to select

**Key:** select

**Type:** text

**Default:** PartNum,PartDescription,ClassID,IUM

#### OData filter

**Key:** filter

**Type:** text

**Default:** InActive eq false

#### Row limit

**Key:** top

**Type:** number

**Default:** 100

#### Output CSV path

**Key:** outfile

**Type:** text

**Default:** C:\Temp\parts.csv

**Blocks:**

#### PowerShell script

**Body:** # Epicor REST v2 query to CSV
# Store the API key and credentials outside the script (environment variables or a secret store).
$server   = "{{server}}"
$instance = "{{instance}}"
$company  = "{{company}}"
$apiKey   = $env:EPICOR_API_KEY
$user     = $env:EPICOR_USER
$pass     = $env:EPICOR_PASS

$pair  = "$($user):$($pass)"
$token = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair))
$headers = @{
  "Authorization" = "Basic $token"
  "x-api-key"     = $apiKey
  "Accept"        = "application/json"
}

$base = "https://$server/$instance/api/v2/odata/$company"
$query = '$select={{select}}&$filter={{filter}}&$top={{top}}'
$uri   ="$base/{{service}}/{{entity}}?" + $query

try {
  $resp = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
  $rows = $resp.value
  Write-Host ("Rows returned: " + $rows.Count)
  $rows | Export-Csv -Path "{{outfile}}" -NoTypeInformation -Encoding UTF8
} catch {
  Write-Error ("Epicor call failed: " + $_.Exception.Message)
  exit 1
}

#### Variant: run a BAQ instead

**Body:** # Replace the URI line with a BAQ call. The BAQ must exist and be available to the REST user.
# $uri = "$base/BaqSvc/YourBaqId/Data?" + '$top={{top}}'

**Notes:** Check three things for your site. First, the URL path (instance and v2 odata pattern) and the authentication method, since some sites use token auth or a different gateway. Second, that the service and entity names exist in your release. Third, that your user has security for the service. Never commit API keys or passwords to source control. The OData options are kept in single quotes so PowerShell does not treat them as variables.

## Content

**Intro:** Pulling data from Epicor into a CSV is a daily need for developers and admins. This generator builds a clean PowerShell script for the Kinetic REST API v2, with credentials kept out of the code.

**Sections:**

#### How to use the generator

**Body:** Enter your server name, instance, company and the business object service you want, for example Erp.BO.PartSvc with the Parts entity. Choose the fields to return, add an OData filter and set a row limit. The script reads the API key and credentials from environment variables, calls the endpoint with Invoke-RestMethod and writes the result to CSV. Copy the code, set the environment variables on the machine that runs it, and run it first with a small row limit.

**Bullets:**

- Set EPICOR_API_KEY, EPICOR_USER and EPICOR_PASS as environment variables
- Start with a top value of 10 or 100
- Confirm the service name in your REST help page
- Schedule only after a successful manual run

#### How the call is built

**Body:** Epicor REST v2 exposes business objects through an OData style path that includes the company. Each request needs an authorization header and an API key header. Query options such as select, filter and top shape the response and reduce the load on the server. A BAQ can be called through the BAQ service with the BAQ ID, which is often the simplest way to return joined data. Responses contain a value array that PowerShell can pipe straight to Export-Csv.

#### Reading the result and paging

**Body:** A successful call prints the number of rows and writes the CSV. If you need more rows than the server returns in one response, page with top and skip, and loop until fewer rows than the page size are returned. Keep pages moderate, such as a few thousand rows, to avoid timeouts. Check dates and decimals in the CSV, since Excel may reformat them when opened.

#### Common mistakes

**Body:** Frequent problems are 401 errors from a missing API key header, 403 errors when the user lacks security for the service, and wrong paths from a different instance name. Another is hard coding passwords in the script. Use a secret store or protected environment variables, and use a dedicated integration user with minimum rights. Do not call write methods from a script before testing in a non production environment.

**Bullets:**

- 401 usually means credentials or API key headers are wrong
- 403 usually means missing security on the service
- 404 usually means a wrong instance or service name
- Never store secrets in the script

**Cta:** If you build many Epicor integrations and extracts, Netray can discuss a governed, read-only data layer or assistant that runs on your own infrastructure.

**Faq:**

#### How do I authenticate to the Epicor REST API from PowerShell?

**Answer:** Most sites send a Basic authorization header with the user name and password plus an x-api-key header. Some environments use token based authentication instead, so confirm the method with your Epicor administrator before building the script.

#### What is the difference between REST v1 and v2?

**Answer:** Version 2 offers an OData style interface with a company segment in the path and supports query options such as select, filter and top. Version 1 uses a different path pattern. Check which versions your instance exposes in the REST help page.

#### Can I call a BAQ from the REST API?

**Answer:** Yes. BAQs can be called through the BAQ service by passing the BAQ ID, and they return their result set as JSON. The BAQ must be published and your user must have access to it.

#### How do I avoid timeouts on large extracts?

**Answer:** Select only needed fields, filter on a date or key range, and page with top and skip. For very large extracts consider a BAQ or a scheduled export on the server side rather than one big REST call.

## Search terms

epicor rest api powershell, epicor rest api v2 example, epicor odata powershell, epicor baq rest powershell, epicor invoke-restmethod, epicor api key header, epicor kinetic rest script, epicor export to csv powershell

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
