Pass params as done in curl -d

Relative novice Coda Pack developer with packs that are used internally and am able to receive data in sync tables but came across this error recently.

I’m making a call to an api and getting an “Authentication Denied”.

I send data in the fetcher as shown below, expecting it to be formatted as in a successful curl call passing the data in curl -d

The Authentication Denied error occurs when sending data in the body of the call like this:


const SIMIAN_API_KEY = '------------------------'
const BODY  = {'auth_token': SIMIAN_API_KEY,
    'output_format': 'json'}

pack.addSyncTable({
    name: "SimianOpenTickets",
    description: "Simian Media",
    identityName: "SimianMedia",
    schema: SimianMediaSchema,
    formula: {
        name: "SyncSimianMedia",
        description: "Syncs media from Simian.",
        parameters: [],
        execute: async function ([], context) {
        let response = await context.fetcher.fetch({
            method: "POST",
            url: `${URL}`,
            body: JSON.stringify(BODY)
        });
        let results = response.body.results;
        return {
            result: results,
        };
        },
    },
    });


I can mimic the failure in curl this way:

curl “https://buck.gosimian.com/api/simian/get_media?auth_token=-------------------&output_format=json

<?xml version="1.0"?> %

I get successful data when using curl like this (and when using python requests in a different application):

curl https://buck.gosimian.com/api/simian/get_media -d “auth_token=-----------------------&output_format=json”

Thanks, any guidance appreciated!
Rob

The Simian API that I was calling required the params to be in a field called ‘form’ rather than in ‘data’ and data is now being returned.

Glad you figured it out! Yes, -d option in curl usually results in the key value pairs being send using the application/x-www-form-urlencoded content type. As you identified, using the Fetcher in the Packs SDK this can be done by passing the key-value pairs in the form field of the request.

let response = await context.fetcher.fetch({
  method: "POST",
  url: "https://httpbin.org/post",
  form: {
    name: "Alice",
    active: String(true),
    days: String(15),
  },
});