Response from api upopn request a job price returns that dropoffs must be filled

The following code does not produce a price and returns that the dropoffs array needs to be filled. I believe this is s a bug, please advise

const tempJob = {
    "job": {
      "pickup_at": "2023-03-21T016:00:00.000Z",
      "pickups": [
        {
          "address": "32 Coombe Ln, Raynes Park, London SW20 0LA",
          "comment": "Ask Bobby",
          "contact": {
            "firstname": "Bobby",
            "lastname": "Brown",
            "phone": "+33610101010",
            "email": "brown@gmail.com",
            "company": "Pizza Shop"
          }
        }
      ],
      "dropoffs": [
        {
          "package_type": "medium",
          "package_description": "yellow package",
          "client_reference": "ru483jejf98wg",
          "address": "23 Ethelbert Rd, London SW20 8QD",
          "comment": "3nd floor on the right",
          "end_customer_time_window_start": "2023-03-21T16:20:00.000Z",
          "end_customer_time_window_end": "2023-03-21T18:00:00.000Z",
          "contact": {
            "firstname": "Julia",
            "lastname": "Moore",
            "phone": "+33712222222",
            "email": "moore@gmail.com",
            "company": "findchow company"
          }
        }
      ]
    }
};

  const API_KEY = await obtainToken();

  let returnValue = null;

  const url = "https://api.sandbox.stuart.com/v2/jobs/pricing";

  const options = {
    method: "POST",
    headers: {
      Accept: "application/json",
      'Authorization': `Bearer ${API_KEY}`
    },
    body: tempJob
  };
  // console.log(options, 'options');
  await fetch(url, options)
  .then((response) => response.json())
  .then((data) => {
    console.log(data);
    returnValue = data;
  });

  return returnValue;
1 Like

Hello @lmitchsmith,

Your headers must include the Content-Type field with “application/json” as the value and you must parse your payload:

const options = {
  method: "POST",
  headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${API_KEY}`
   },
  body: JSON.stringify(tempJob)
};

Also, at the top of our API documentation you can select the programming language in which you are developing (in your case Javascript -Fetch). This way each request example will be provided in the language you selected.

Thank you!

1 Like

Thank you Adrien, I had the incorrect header as you pointed out. Also your advice to toggle the language examples in your docs is invaluable.

3 Likes