"No records were returned" - what am I missing?

I am building a pack to Get a list of data from an API. I can “Build” the pack and access it in my Doc. It shows all the columns, but no records are being returned.

image

I’ve tried the same API endpoint out in Postman and works perfectly. So I guess I’m missing something in my Coda pack code somewhere.

My guess for why it’s not working:

  • I have the authentication part of the code wrong. However, I don’t get a “access denied”, so seems like the authentication is ok. Authentication method is bearer key.
  • In postman, I send “Content-Type: application/json” in the header - is that needed here as well?

Can anyone help? Happy to pay for it as well :slight_smile:

import * as coda from "@codahq/packs-sdk";

export const pack = coda.newPack();

pack.addNetworkDomain("services.foreningsadministrator.dk");

pack.setUserAuthentication({
  type: coda.AuthenticationType.HeaderBearerToken,
  instructionsUrl: "https://help.example.com/api-tokens",
  getConnectionName: async function (context) {
    // TODO: Fetch the name of the account.
    let name = "";
    return name;
  },
});

//What information to expect and then to populate in my sync table

const Member_Schema = coda.makeObjectSchema({
  properties: {
    MemberNumber: { type: coda.ValueType.Number },
    Firstname: { type: coda.ValueType.String }
  },
  displayProperty: "Firstname",
  idProperty: "MemberNumber",
  featuredProperties: ["MemberNumber", "Firstname"]
});

pack.addSyncTable({
  name: "Medlemmer",
  description: "Liste med alle medlemmer på Foreningsadministrator",
  identityName: "FirstName",
  schema: Member_Schema,
  formula: {
    name: "Sync",
    description: "Syncs the data.",
    parameters: [
      // TODO: Add parameters.
    ],
    execute: async function ([], context) {
      let url = "https://services.foreningsadministrator.dk/custom/kundenavn/members/memberlist";
      let response = await context.fetcher.fetch({
        method: "GET",
        url: url,
      });
      let items = response.body.resultdata;
      return {
        result: items,
      };
    },
  },
});

Hey there! Can you send a screenshot of the raw response? Maybe from postMan?

My guess is either:

  1. Your Id key of MemberNumber is incorrect
  2. The array of data in the response is at a different path than your defined response.body.resultdata or that you misspelled resultdata

Thanks for pitching in. I actually just followed your “Build-a-pack” video to get to this stage :clap:t2:

Just checked the logs. It seems like my API key is missing.

image

I put in the bearer token here, so I am assuming that should be correct.
image

1 - Id key of MemberNumber is incorrect: Can you clarify?
2 - It is resultdata

image

Nope I was wrong with my assumptions - you’re good with your code

It’s just an authentications issue.

Can you unroll the “headers” part of your pack logs?

And where’s the documentation for your api? Maybe you don’t need a header bearer token

Unrolled headers:

No public documentation for the API. It’s custom for the use case.

Example curl request:

curl --location --request POST
'https://services.foreningsadministrator.dk/custom/clientname/members
–header ‘Authorization: Bearer API-KEY-HERE’
–header ‘Content-Type: application/json’
–data-raw ‘{“json”:“postdata”,“placed”:[“in”,“here”]}’

In Postman, I authenticate like this:
Skærmbillede 2023-08-23 kl. 18.54.37

Thank you so much for taking the time to help out - super appreciated!

Hi @Maja_Overgard - I agree with @Scott_Collier-Weir, your code looks pretty good, so hard to tell what’s going wrong.

Can you unroll the “headers” part of your pack logs?

What Scott means here is can you expand the “headers” node of the request log, so we can see what headers were sent.

a7c1847e3a4c25b3213f0a9b0c39598aa7ee9938

I’d also try signing into the Pack account again, making sure that there isn’t any extra spaces before or after the API key. It could be that the API reports a missing API key for an incorrect one, and extra spaces could be enough to throw it off.

P.S. - I’m also happy to help debug your code live in Office Hours. You can sign up here: How to get help - Coda Pack SDK

Ahh gotha.

Headers unrolled here:

image

That does seem to indicate that the API key is being sent in the correct location. I’d double check that you pasted it in correctly, with no extra whitespace,

Tried multiple times now. The API key is pasted correctly.

I’ve booked a time with you Monday, Eric. Looking forward to it!

2 Likes