How Do I Use Access Token to make API request

I have been able to generate my ACCESS TOKEN by using my account CLIENT ID and CLIENT SECRET KEY. My challenge is that even though I am passing the ACCESS TOKEN in the request header of the API for getting price, I got error in the API response. The error message is: ```
{
“error”: “INVALID_GRANT”,
“message”: “The access token was revoked”
}

My question now is where should I use the access token to make a successful request

Hello @Matthew,

You received this error because your token is no longer valid.
Please, generate a new access token using the authentication endpoint with your client_id and client_secret.

Note that access tokens have an expiration time of 1 month. You must therefore make sure to manage the automatic renewal of your token.

More information about authentication can be found here.

Thank you!

Thank you @Adrien,

The thing is that I am just integrating this APIs and have the token generated yesterday. I have tried to see where you passed the access token in your APIs but I could not find it in any of the APIs in the documentation.

I have used my discretion and passed it in my request header but still getting the error. I think what I want to hear from you is where the token should be added to the request. Where should I pass it in my request so that I can make a successful request. I am currently developing on my local machine and using the sandbox APIs.

Thanks!

Hi @Matthew,

You must pass it in your headers in the Authorization field.
Please make sure to add "Bearer " before the token as below:

GET https://api.sandbox.stuart.com/some_endpoint HTTP/1.1
Authorization: Bearer [token]
Host: api.sandbox.stuart.com

Several sample requests can be found in our [API documentation] (https://api-docs.stuart.com/). At the top of the page, you can select the language in which you want to make the request.

Cheers!

Thank you @Adrien. I have got working

1 Like

Hi @Adrien,

In the code snippet below, what should I use as the values of ACCESS_CODES?

{
                "package_type": "medium",
                "package_description": "yellow package",
                "client_reference": "w43uiuirw3hre343",
                "address": "23 Ethelbert Rd, London SW20 8QD",
                "comment": "3nd floor on the right",
                "end_customer_time_window_start": "2021-12-12T11:00:00.000+02:00",
                "end_customer_time_window_end": "2021-12-12T13:00:00.000+02:00",
                "contact": {
                    "firstname": "Julia",
                    "lastname": "Moore",
                    "phone": "+33712222222",
                    "email": "client3@email.com",
                    "company": "Sample Company Inc."
                },
                "access_codes": [
                    {
                        "code": "your_access_code_2",
                        "type": "text",
                        "title": "access code title",
                        "instructions": "please put your instructions here"
                    }
                ]
            }

Hi @Matthew ,

The access_code field is optional. You can use it if you want the courier to have a specific way of validating his tasks (pickup and/or drop-off). There are several types of access codes. Depending on the type of access code that you provide the courier may have to:

  • Scan a barcode or a QR Code
  • Show a barcode, a QR Code, or a text
  • Enter a code (e.g for accessing a building)

You can check out this article for more information.

Thank you

Hi @Adrien,

Oh I am just seeing your reply. I even created a new topic on this issue this morning before I saw this reply. You can ignore my latest question then.

Thanks

Hi @Matthew,

No problem. I’m glad I could help you.

Thank you!

Hi @Adrien,

Please check my request payload below and let me know what I am doing wrong. I tried calling the API to get price but got error below:

    "message": "Unable to save record",
    "data": {
      "job.dropoffs": [
        "must be filled"
      ]
    }

My payload is:

  "jobs": {
    "pickup_at": "2023-02-21T09:00:00.000Z",
    "pickups": [
      {
        "address": "32 Coombe Ln, Raynes Park, London SW20 0LA",
        "comment": "Ask Bobby",
        "contact": {
          "firstname": "Bobby",
          "lastname": "Brown",
          "phone": 33610101010,
          "email": "bobby.brown@pizzashop.com",
          "company": "Pizza Shop"
        }
      }
    ],
    "dropoffs": [
      {
        "package_type": "medium",
        "package_description": "yellow package",
        "client_reference": "ru483jejf98w",
        "address": "23 Ethelbert Rd, London SW20 8QD",
        "comment": "3nd floor on the right",
        "end_customer_time_window_start": "2021-12-12T09:00:00.000Z",
        "end_customer_time_window_end": "2021-12-12T11:00:00.000Z",
        "contact": {
          "firstname": "Julia",
          "lastname": "Moore",
          "phone": "33712222222",
          "email": "client3@email.com",
          "company": "Sample Company Inc."
        }
      }
    ]
  }
}```

Hello @Matthew,

I spotted two errors in the payload you provided:

  • There is a typo in the name of the job field. You added an extra “s” to the field name.
  • The phone number you provided for the pickup is of type integer instead of string.

You should be able to successfully create a new job by fixing these errors.

Also, don’t forget to change the pickup date, as it is already passed.

Thank you

1 Like

Hi @Adrien,

Thank you for your response. I wish to inform you that I have effected the changes you recommended but I am still facing the same challenge. Below is the updated request payload:

{
  "job": {
    "pickup_at": "2023-02-23T011: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": "ru483jejf98w",
        "address": "23 Ethelbert Rd, London SW20 8QD",
        "comment": "3nd floor on the right",
        "end_customer_time_window_start": "2023-02-23T11:10:00.000Z",
        "end_customer_time_window_end": "2023-02-23T02:00:00.000Z",
        "contact": {
          "firstname": "Julia",
          "lastname": "Moore",
          "phone": 33712222222,
          "email": "moore@gmail.com",
          "company": "findchow company"
        }
      }
    ]
  }
}```

Please take a look at it and let me know what I should do better to make the request go through.

Thanks

Hello @Matthew,

Sorry for the misunderstanding.
Our API expects a string value for phone numbers (for both pickup and dropoff).

This should be the reason why your request could not succeed.

Thank you

Hi @Adrien,

I have just updated the payload with the phone number passed as string but it still did fail.

  "job": {
    "pickup_at": "2023-02-23T011: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": "ru483jejf98w",
        "address": "23 Ethelbert Rd, London SW20 8QD",
        "comment": "3nd floor on the right",
        "end_customer_time_window_start": "2023-02-23T11:10:00.000Z",
        "end_customer_time_window_end": "2023-02-23T02:00:00.000Z",
        "contact": {
          "firstname": "Julia",
          "lastname": "Moore",
          "phone": "+33712222222",
          "email": "moore@gmail.com",
          "company": "findchow company"
        }
      }
    ]
  }
}

The response from the request is:

    "message": "Unable to save record",
    "data": {
      "job.dropoffs": [
        "must be filled"
      ]
    }

Hi @Matthew,

Below you can find an example of a valid payload:

{"job": {
    "pickup_at": "2023-02-23T016: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-02-23T11:10:00.000Z",
        "end_customer_time_window_end": "2023-02-23T02:00:00.000Z",
        "contact": {
          "firstname": "Julia",
          "lastname": "Moore",
          "phone": "+33712222222",
          "email": "moore@gmail.com",
          "company": "findchow company"
        }
      }
    ]
  }
}

For testing, you can use our postman collection. It is accessible in the header of our API documentation by clicking on the “Run in Postman” button (See the following screenshot).

Thank you