Skip to content

Post action creates invalid URI #28

@rjwhitmer

Description

@rjwhitmer

As currently outlined in the docs, generating a post request creates an invalid URI as seen here:

fulfil = Fulfil::Client.new

sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')

sale = {
  # Full Sale attributes here
}

fulfil.post(model: sale_model, body: sale)

When attempting to follow that convention, the resulting output is as follows:

def fulfil_client_model
  Fulfil::Model.new(client: FulfilClient, model_name: 'party.party')
end

FulfilClient.post(body: [{ 'name' => contact.name }], model: fulfil_client_model)

>URI::InvalidURIError (bad URI(is not URI?): "https://lcf.fulfil.io/api/v2/model/#<Fulfil::Model:0x00007f6b23a45b60>")

This error shows that the post method is incorrectly parsing the model_name from the model object, and is instead passing the entire object, causing the error. However, passing fulfil_client_model.model_name will generate the proper URI allowing the request to Fulfil.

# Customer information hidden

FulfilClient.post(body: [{ 'name' => contact.name }], model: fulfil_client_model.model_name)

I, [2022-05-26T10:30:29.139171 #15871]  INFO -- : > POST https://<fulfil_client>/api/v2/model/party.party
D, [2022-05-26T10:30:29.139396 #15871] DEBUG -- : X-Api-Key: <API_KEY>
Connection: close
Content-Type: application/json; charset=UTF-8
Host: <fulfil_client>
User-Agent: http.rb/5.0.4

[{"name":"Bob Whitmer"}]
I, [2022-05-26T10:30:29.979899 #15871]  INFO -- : < 201 Created
D, [2022-05-26T10:30:29.980201 #15871] DEBUG -- : Server: openresty/1.15.8.1
Date: Thu, 26 May 2022 16:30:29 GMT
Content-Type: application/json
Content-Length: 42
X-EXEC-TIME: 104.9185
X-REPSONSE-TIME: 174.0932
X-ATTEMPTS: 1
X-REQUEST-ID: req_2c17305fb699c9a9ef69addaad8e3e36
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 9
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Vary: Cookie
Set-Cookie: session=eyJfcGVybWFuZW50Ijp0cnVlfQ.Yo-rJQ.9gYKY6Ku96YW6RkoZ6eOyK8-YCs; Expires=Thu, 26 May 2022 17:30:29 GMT; Secure; HttpOnly; Path=/
Content-Security-Policy-Report-Only: default-src 'self' https: data: 'unsafe-inline'; connect-src 'self' https: https://*.hotjar.com:* https://vc.hotjar.io:* wss://*.hotjar.com; img-src 'self' https: data:; media-src 'self' https: data:; script-src 'self' https://*.fulfil.io https://cdn.pubnub.com https://maps.googleapis.com https://apis.google.com https://cdn.mxpnl.com https://*.hotjar.com https://js.stripe.com https://www.gstatic.com; frame-ancestors 'self'; report-uri https://us-central1-fulfil-production-v2.cloudfunctions.net/csp-report-uri;
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

[{"id":8678380,"rec_name":"Bob Whitmer"}]

I would suggest either updating the documentation to make it clearer that the model_name attribute needs to be passed into the post request, or update the model_url method to return the model_name attribute, as opposed to the entire object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions