Access token issues

Hello I’m using the code below from your documentation but I have this message error : => "{\"error\":\"INVALID_GRANT\",\"message\":\"The access token was revoked\"}"

However, I also used the code to have the access token but i don’t know where I should put it in the code for the Job creation. Can you help me? thanks !!

require "uri"
require "json"
require "net/http"

url = URI("https://api.sandbox.stuart.com/v2/jobs")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request.body = JSON.dump({
  "job": {
    "pickups": [
      {
        "address": "32 Coombe Ln, Raynes Park, London SW20 0LA",
        "comment": "Ask Bobby",
        "contact": {
          "firstname": "Bobby",
          "lastname": "Brown",
          "phone": "+33610101010",
          "email": "bobby.brown@pizzahut.com",
          "company": "Pizza Hut"
        },
        "access_codes": [
          {
            "code": "your_access_code_1",
            "type": "text",
            "title": "access code title",
            "instructions": "please put your instructions here"
          }
        ]
      }
    ],
    "dropoffs": [
      {
        "package_type": "medium",
        "package_description": "yellow package",
        "client_reference": "[your_client_ref]",
        "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"
          }
        ]
      }
    ]
  }
})

response = https.request(request)
puts response.read_body
1 Like

Hello @willguill,

I just replied to your former post.
I recommend that you read my reply and use our client library instead of your own implementation. This will allow you among other things to use your token more easily.

Now to answer this post, your access token should be included in your headers for all the requests you send to the Stuart API. It must be provided under the Authorization field.

In your example, it would look like this:

url = URI("https://api.sandbox.stuart.com/v2/jobs")
access_token = "YOUR ACCESS TOKEN" # New line

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer #{access_token}" # New line

# Rest of your code

You can find information about our OAuth Authentication best practices here.

Cheers