[RUBY] Memorandum: What I was addicted to when I hit the accounting freee API

When specifying a query with GET, let's communicate with http with uri.request_uri properly.

It's all about this, not the API specifications of accounting freee, but just my own mistake.

Hit with ruby

ACCESS_TOKEN has been acquired with OAuth 2.0. Set the parameters like this

BASE_URL = 'https://api.freee.co.jp'
MY_COMPANY_ID = '*********'
USE_ACCESS_TOKEN_HEADER = {
  "accept" => "application/json",
  "Authorization"=> "Bearer *************************"
}

I hit the API to get the details of the business partner as follows (It's a fairly simple method that is easy to understand)

def get_torihikisaki_id(name)
   uri = URI.parse(BASE_URL + '/api/1/partners')
   uri.query = URI.encode_www_form({"company_id" => MY_COMPANY_ID ,'keyword'=> name})
   http = Net::HTTP.new(uri.host, uri.port)
   http.use_ssl = true
   headers = USE_ACCESS_TOKEN_HEADER
   response = http.get(uri.path, headers)
   res_hash = JSON.parse(response.body)
end

puts get_torihikisaki_id('hoge co')

The response was like this.

{"status_code"=>400, "errors"=>[{"type"=>"validation", "messages"=>["company_id is not specified."]}]}

I'm specifying company_id ~ I wonder why I've thought a lot.

Cause

This sentence

response = http.get(uri.path, headers)

http communication was performed only with uri.path. I'm not using it to set the query ... Correctly

response = http.get(uri.request_uri, headers)

When embedding parameters in url with GET, you have to use it properly ...

Dedicated every day

Recommended Posts

Memorandum: What I was addicted to when I hit the accounting freee API
What I was addicted to when introducing the JNI library
What I was addicted to with the Redmine REST API
A story I was addicted to when testing the API using MockMVC
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
The story I was addicted to when setting up STS
I was addicted to the roll method
I was addicted to the Spring-Batch test
What I was addicted to when implementing google authentication with rails
I was addicted to the API version min23 setting of registerTorchCallback
[Rails] I was addicted to the nginx settings when using Action Cable.
What I was addicted to when updating the PHP version of the development environment (Docker) from 7.2.11 to 7.4.x
Problems I was addicted to when building the digdag environment with docker
I was addicted to the NoSuchMethodError in Cloud Endpoints
I was addicted to the record of the associated model
What I was addicted to when developing a Spring Boot application with VS Code
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
What I was addicted to while using rspec on rails
I was addicted to looping the Update statement on MyBatis
I was addicted to the setting of laradock + VSCode + xdebug
I was addicted to using Java's Stream API in Scala
I was addicted to starting sbt
I tried to summarize what was asked at the site-java edition-
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
About the matter that I was addicted to how to use hashmap
I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest
I tried to summarize the Stream API
What I thought when passing the user input value to the Service class
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
Recorded because I was addicted to the standard input of the Scanner class
I was addicted to scrollview because I couldn't tap the variable size UIView
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was addicted to unit testing with the buffer operator in RxJava
What I tried when I wanted to get all the fields of a bean
I was addicted to installing Ruby/Tk on MacOS
I was addicted to doing onActivityResult () with DialogFragment
I was addicted to not being able to connect to AWS-S3 from the Docker container
I was a little addicted to the S3 Checksum comparison, so I made a note.
When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API
What I did when I converted java to Kotlin
What I did when I was addicted to the error "Could not find XXX in any of the sources" when I added a Gem and built it
A memo that I was addicted to when making batch processing with Spring Boot
[Summary] What I noticed and did when I was told that the Oracle JDK was paid
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
I want to hit the API with Rails on multiple docker-composes set up locally
A story I was addicted to when getting a key that was automatically tried on MyBatis
What to do when The SSL certificate has expired
What should I do to reload the updated Dockerfile?
When I tried to scroll automatically with JScrollBar, the event handler was drawn only once.
I was addicted to WSl when trying to build an android application development environment with Vue.js
I was addicted to setting default_url_options with Rails devise introduction
I want to use the Java 8 DateTime API slowly (now)
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
A story I was addicted to in Rails validation settings
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
[Rails] How to solve ActiveSupport :: MessageVerifier :: InvalidSignature that I was addicted to when introducing twitter login [ActiveStorage]
[Words spelled to me when I was in the first grade ⑦] What I want you to include at least with the Visual Studio Code extension
I knew what reflection was
[Circle CI] A story I was addicted to at Start Building
What to do when the changes in the Servlet are not reflected