# Excel and Power Query (/docs/integrations/excel) Pull social media data into Excel and Power Query without writing a server. You can load SocialCrawl data into Excel with a Power Query that calls the API. One query returns a table that refreshes with Data, then Refresh All. Setup takes three steps: name the key, write the query, load the table. ## Before you start Create an API key in the dashboard under API Keys. Prove the key with a call that costs nothing: ```bash title="Check the key (0 credits)" curl "https://www.socialcrawl.dev/v1/credits/balance" \ -H "x-api-key: sc_your_key_here" ``` A reply with `"success": true` and your balance in `data.balance` means the key works. The key has to reach the query's `x-api-key` header. Power Query has no secret store for a header value, so the key lives in the workbook. Put it in one cell named `ApiKey` on a Settings sheet, and clear that cell before you share the file. ## Connect In Excel, open Data, then Get Data, then From Other Sources, then Blank Query. Open the Advanced Editor and paste this: ```powerquery title="Power Query (M)" let Key = Excel.CurrentWorkbook(){[Name = "ApiKey"]}[Content]{0}[Column1], Source = Web.Contents( "https://www.socialcrawl.dev/v1/tiktok/profile/videos?handle=mrbeast", [ Headers = [#"x-api-key" = Key], ManualStatusHandling = {402, 429} ] ), Body = Json.Document(Source), Items = Body[data][items], Table = Table.FromRecords(Items) in Table ``` `ManualStatusHandling` lets the query read a 402 or 429 answer instead of stopping with an error. Replace the path and the query to call any other endpoint. ## Read the answer Every response has the same shape. Branch on `success`. A list puts its rows in `data.items`, and `pagination.next_cursor` is the token for the next page. ```json title="Response (trimmed)" { "success": true, "data": { "items": [{ "id": "7654638524729216287" }] }, "pagination": { "next_cursor": "sc.eyJ2Ijoy…", "has_more": true }, "credits_used": 1, "credits_remaining": 99 } ``` To read the next page, add `&cursor=` and the `next_cursor` value to the URL, and stop when `has_more` is `false`. See [Pagination](/docs/pagination.md). ## When it stops A failed refresh shows an error in the query pane. It does not send an email. With `ManualStatusHandling` set, the query receives the body of a 402 or 429 answer, so test `Body[success]` and show `Body[error][message]` in a cell. When credits run out, the status is 402 and `error.type` is `INSUFFICIENT_CREDITS`. Read `error.message` for the text and `error.details.checkout_url` for the link that opens checkout. When the link is absent, `error.details.top_up_url` opens the billing page. Never retry a 402, because it fails until credits are added. Retry a 429 after the seconds in the `Retry-After` header, and a 502, 503 or 504 after a short backoff. See [Errors](/docs/errors.md). ## What a run costs It depends on the endpoint, and some endpoints are priced by what they return. [Endpoint pricing](/docs/endpoint-pricing.md) lists each one, and [Credits](/docs/credits.md) explains cache hits and refunds. Every refresh runs the call again, so a query that refreshes on open costs credits each time. `GET /v1/utility/estimate` quotes a call for 0 credits. - [Errors](/docs/errors.md): Every error code, with the fix and whether to retry. - [Pagination](/docs/pagination.md): One cursor rule for every list endpoint. - [Endpoint pricing](/docs/endpoint-pricing.md): What each endpoint costs before a refresh runs it.