Forum Discussion
New API connection
- 8 months ago
okay maybe you will need to pass the token as a function then , try to created the following function and query
open blank query and copy past , name the function as GetTokenNew
() as text => let // ----------------------------- // ECI OAuth Token Request // ----------------------------- client_id = "YOUR_CLIENT_ID", client_secret = "YOUR_CLIENT_SECRET", token_url = "https://api-user.integrations.ecimanufacturing.com/oauth2/api-user/token", tokenBody = "grant_type=client_credentials" & "&scope=openid" & "&client_id=" & client_id & "&client_secret=" & client_secret, tokenResponse = Json.Document( Web.Contents( token_url, [ Headers = [ #"Content-Type" = "application/x-www-form-urlencoded", Accept = "application/json" ], Content = Text.ToBinary(tokenBody) ] ) ), // Extract raw token access_token = tokenResponse[access_token], // Return as "Bearer xxxx" BearerToken = "Bearer " & access_token in BearerTokencreate another query and past
let // Call token function BearerToken = GetTokenNew(), api_url = "https://api-jb2.integrations.ecimanufacturing.com/api/v1/job-materials", apiResponse = Json.Document( Web.Contents( api_url, [ Headers = [ Authorization = BearerToken, Accept = "application/json" ] ] ) ), // Convert list/record into table AsList = if apiResponse is list then apiResponse else if apiResponse is record and Record.HasFields(apiResponse, "data") then apiResponse[data] else {}, TableOut = if List.Count(AsList) > 0 then let tbl = Table.FromList(AsList, Splitter.SplitByNothing(), null, null, ExtraValues.Error), firstRecord = tbl{0}[Column1], expanded = Table.ExpandRecordColumn(tbl, "Column1", Record.FieldNames(firstRecord)) in expanded else #table({}, {}) in TableOutbut it's better if you change the get-schedule url(in the first working query) and get the job-materials value in one query first , then try above method
- 8 months ago
Hi Anonymous
Can you try this code and see if it returns a value to pages step ?
let // --------------------------------------------------- // 1. OAuth Token Request (leave your real values) // --------------------------------------------------- client_id = "YOUR_CLIENT_ID", client_secret = "YOUR_CLIENT_SECRET", token_url = "https://api-user.integrations.ecimanufacturing.com/oauth2/api-user/token", tokenResponse = Json.Document( Web.Contents( token_url, [ Headers = [ #"Content-Type" = "application/x-www-form-urlencoded", Accept = "application/json" ], Content = Text.ToBinary( "grant_type=client_credentials" & "&scope=openid" & "&client_id=" & client_id & "&client_secret=" & client_secret ) ] ) ), access_token = tokenResponse[access_token], // --------------------------------------------------- // 2. Paging Function // --------------------------------------------------- PageSize = 200, GetPage = (Skip as number) => let url = "https://api-jb2.integrations.ecimanufacturing.com/api/v1/job-materials" & "?take=" & Number.ToText(PageSize) & "&skip=" & Number.ToText(Skip), response = Json.Document( Web.Contents( url, [ Headers = [ Authorization = "Bearer " & access_token, Accept = "application/json" ] ] ) ), // FIXED: correct field is "Data" (case-sensitive) items = if response is list then response else if response is record and Record.HasFields(response, "Data") then response[Data] else {} in items, // --------------------------------------------------- // 3. Generate pages until empty page encountered // --------------------------------------------------- Pages = List.Generate( () => [Skip = 0, Data = GetPage(0)], each List.Count([Data]) > 0, each [Skip = [Skip] + PageSize, Data = GetPage([Skip] )], each [Data] ), AllItems = List.Combine(Pages), // --------------------------------------------------- // 4. Convert to Table and Expand // --------------------------------------------------- Output = if List.Count(AllItems) = 0 then #table({}, {}) else let tbl = Table.FromList(AllItems, Splitter.SplitByNothing(), null, null, ExtraValues.Error), firstRecord = tbl{0}[Column1], fieldNames = Record.FieldNames(firstRecord), expanded = Table.ExpandRecordColumn(tbl, "Column1", fieldNames, fieldNames) in expanded in Output
Hi kushanNa ,
Apology if I disturb you but I'm in trouble with it.
Do you had my message. Any thoughts?
Kind regards
Giovanni
Hi Anonymous
No worries, What do you see in the step after GetPage step?
- Anonymous8 months agoNot applicable
- Anonymous8 months agoNot applicable
Hi kushanNa
GetPages asking for a Skip and in my previous message I reported any values I can use it will invoke a function with error.
Pages at the moment returning an emapty list.
Thanks
Giovanni
- kushanNa8 months agoSuper User
Okay, this is the problem ,I think the API is not returning any data.
You mentioned that you were able to get job-materials from a query, right?
Which query did you use to get it?Please try refreshing that query and check whether you can still retrieve the data.
If you can, copy that query here. - Anonymous8 months agoNot applicable
Hi kushanNa
True but the limitation is I can pull only 1000 rows and I need the full dataset of data.
We achieve that with 2 scripts:
1 - Token Script
2- Pull job-materials data
As the token part has not been modified here only the script of job-materials:
let
// Call token function
BearerToken = GetTokenNew(),api_url = "https://api-jb2.integrations.ecimanufacturing.com/api/v1/job-materials",
apiResponse =
Json.Document(
Web.Contents(
api_url,
[
Headers = [
Authorization = BearerToken,
Accept = "application/json"
]
]
)
),
Data = apiResponse[Data],
#"Converted to Table" = Table.FromList(Data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"jobStatus", "jobClosedDate", "orderNumber", "jobNumber", "partNumber", "description", "stepNumber", "binLocation1", "quantityPosted1", "binLocation2", "quantityPosted2", "binLocation3", "quantityPosted3", "binLocation4", "quantityPosted4", "binLocation5", "quantityPosted5", "datePosted", "stockingCost", "stockUnit", "postedBy", "resalePrice", "pricingUnit", "productCode", "GLCode", "vendorCode", "vendorInvoiceNumber", "PONumber", "PODate", "vendorType", "receiverNumber", "packingListNumber", "receiverDate", "packingListDate", "lotNumber1", "lotNumber2", "lotNumber3", "lotNumber4", "lotNumber5", "uniqueID", "binLocationCounter", "originalBinCost", "subAssemblyJobNumber", "manufacturingJobNumber", "lastModDate", "lastModUser", "POItemNumber", "mainPart", "outsideService", "postedFromStock"}, {"Column1.jobStatus", "Column1.jobClosedDate", "Column1.orderNumber", "Column1.jobNumber", "Column1.partNumber", "Column1.description", "Column1.stepNumber", "Column1.binLocation1", "Column1.quantityPosted1", "Column1.binLocation2", "Column1.quantityPosted2", "Column1.binLocation3", "Column1.quantityPosted3", "Column1.binLocation4", "Column1.quantityPosted4", "Column1.binLocation5", "Column1.quantityPosted5", "Column1.datePosted", "Column1.stockingCost", "Column1.stockUnit", "Column1.postedBy", "Column1.resalePrice", "Column1.pricingUnit", "Column1.productCode", "Column1.GLCode", "Column1.vendorCode", "Column1.vendorInvoiceNumber", "Column1.PONumber", "Column1.PODate", "Column1.vendorType", "Column1.receiverNumber", "Column1.packingListNumber", "Column1.receiverDate", "Column1.packingListDate", "Column1.lotNumber1", "Column1.lotNumber2", "Column1.lotNumber3", "Column1.lotNumber4", "Column1.lotNumber5", "Column1.uniqueID", "Column1.binLocationCounter", "Column1.originalBinCost", "Column1.subAssemblyJobNumber", "Column1.manufacturingJobNumber", "Column1.lastModDate", "Column1.lastModUser", "Column1.POItemNumber", "Column1.mainPart", "Column1.outsideService", "Column1.postedFromStock"})
in
#"Expanded Column1" - kushanNa8 months agoSuper User
Hi Anonymous
Can you try this code and see if it returns a value to pages step ?
let // --------------------------------------------------- // 1. OAuth Token Request (leave your real values) // --------------------------------------------------- client_id = "YOUR_CLIENT_ID", client_secret = "YOUR_CLIENT_SECRET", token_url = "https://api-user.integrations.ecimanufacturing.com/oauth2/api-user/token", tokenResponse = Json.Document( Web.Contents( token_url, [ Headers = [ #"Content-Type" = "application/x-www-form-urlencoded", Accept = "application/json" ], Content = Text.ToBinary( "grant_type=client_credentials" & "&scope=openid" & "&client_id=" & client_id & "&client_secret=" & client_secret ) ] ) ), access_token = tokenResponse[access_token], // --------------------------------------------------- // 2. Paging Function // --------------------------------------------------- PageSize = 200, GetPage = (Skip as number) => let url = "https://api-jb2.integrations.ecimanufacturing.com/api/v1/job-materials" & "?take=" & Number.ToText(PageSize) & "&skip=" & Number.ToText(Skip), response = Json.Document( Web.Contents( url, [ Headers = [ Authorization = "Bearer " & access_token, Accept = "application/json" ] ] ) ), // FIXED: correct field is "Data" (case-sensitive) items = if response is list then response else if response is record and Record.HasFields(response, "Data") then response[Data] else {} in items, // --------------------------------------------------- // 3. Generate pages until empty page encountered // --------------------------------------------------- Pages = List.Generate( () => [Skip = 0, Data = GetPage(0)], each List.Count([Data]) > 0, each [Skip = [Skip] + PageSize, Data = GetPage([Skip] )], each [Data] ), AllItems = List.Combine(Pages), // --------------------------------------------------- // 4. Convert to Table and Expand // --------------------------------------------------- Output = if List.Count(AllItems) = 0 then #table({}, {}) else let tbl = Table.FromList(AllItems, Splitter.SplitByNothing(), null, null, ExtraValues.Error), firstRecord = tbl{0}[Column1], fieldNames = Record.FieldNames(firstRecord), expanded = Table.ExpandRecordColumn(tbl, "Column1", fieldNames, fieldNames) in expanded in Output