facebook-ruby-business-sdk
facebook-ruby-business-sdk copied to clipboard
When successful in creating a custom conversion, the response body is incorrect and generates a JSON::ParserError
Which SDK version are you using?
0.12.0.1
What's the issue?
When successful in creating a custom conversion through the API, the response body is incorrect and generates a JSON::ParserError.
Steps/Sample code to reproduce the issue
First we generate a hash called facebook_attributes that we will use as params for our API call:
facebook_attributes = {
name: "test_mth",
description: "Tracks when something happens",
rule: "{\"and\":[{\"event\":{\"eq\":\"PageView\"}},{\"or\":[{\"URL\":{\"i_contains\":\"some_url\"}}]}]}",
event_source_id: our_facebook_pixel_id
}
Second we make a call to Facebook API:
custom_conversion = FacebookAds::AdAccount
.get("act_#{our_facebook_ad_account_id}")
.customconversions
.create(facebook_attributes)
Observed Results:
We have the following error indicating the we try to parse something that is not parseable:
JSON::ParserError: 859: unexpected token at 'Sorry, this content isn't available right now'
from /Users/mathieu/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.6.1/lib/json/common.rb:216:in `parse'
Doing some research, it comes from the fact that we try to parse the response body which is equal to 'Sorry, this content isn't available right now', this causes a JSON::ParserError.
File responsible: lib/facebook_ads/api_response.rb
Code responsible:
module FacebookAds
class APIResponse
attr_reader :status_code, :headers, :body
def initialize(status_code, headers, body)
@status_code = status_code
@headers = headers
@body = body
end
def result
is_json_response? ? **JSON.parse(body)** : body
end
...
end
end
Expected Results:
It should:
- Be able to handle a response body of type 'Sorry, this content isn't available right now' and not cause a JSON::ParserError
- Sends us back the id of the custom conversion created