Offers API Syntax

When attempting to use the offers API to post an offer in the test environment. I’m receiving the following error: HTTP400: Bad Request - The request could not be processed by the server due to invalid syntax. I’ve reviewed the API documentation and my code, see below, but can’t figure out why this isn’t posting. I replaced my API key with ‘XXXX’ for the purpose of this message.

Hi @rknapp,

Thanks for trying out our offers API! Unfortunately, your code didn’t post in your message, so I can’t troubleshoot. I did just run the following:

curl -X POST https://api.fidel.uk/v1/offers  \
-H 'content-type: application/json' -H 'fidel-key: {my key}' \
-d '{   "countryCode": "IRL", "name":"42% off Lemonade",\
"additionalTerms": "No Ducks.  Not valid on glue.", \
"publisherId":"fec57ce7-d161-4c8f-8da0-1ebf841f4739",\
"brandId":"0b7b83a3-ccb3-4854-804a-90e5d951d1eb",\
"startDate":"2020-05-01","type":{"name":"discount","value":42}}'

and I received a 201 response, and I see the following pending offer in my Dashboard:

Please post your code, and we’ll give it a debug.

Doug

var url = “https://api.fidel.uk/v1/offers”;

var offer = {
“countryCode”: “USA”,
“name”:“20% Off Everything”,
“brandId”:“450fe546-33f2-4e80-81e0-9dbeb84986a8”,
“publisherId”:“afc160d2-c4a1-4a17-89e6-de541ecd7e48”,
“startDate”:“2020-04-20T12:13:13.000Z”,
“type”:{
“name”:“Super Sale”,
“value”:20,
}
};

const request = new Request(url, {
method: ‘POST’,
headers: new Headers({
‘content-type’: ‘application/json’,
‘fidel-key’: ‘xxxx’,
}),
body: JSON.stringify(offer),
});

fetch(request)
.then(res => res.json())
.then(res => console.log(res));

Hi @rknapp I can replicate your error. There is a defect in the way we post the startDate - if you attempt to set the date AND the time, you’ll get an error. Just the date works. We will have a fix deployed on Monday.

This weekend, you can use “YYYY-MM-DD” to set the offer start date (and it will default to midnight start time). Next week, we can return to setting a time. :alarm_clock:

Thanks!
Doug

Thanks for the reply Doug. I look forward to working more with the test environment. I changed my startDate to read

“startDate”:“2020-06-20”,

However, I still get the same error. From what you can tell, is the code I sent you correct otherwise?

So… I’ve been working with the dev team on this one all day, and it appears that now - it is breaking on the date parameter (inserted on the backend). For example - I used the correct startDate, but it failed on 2020-05-01T12:13:00.000Z (today at noon GMT) for the date field.

We’ll get this sorted on Monday. Apologies for the delay.

Not a problem. Thank you for being available to work with me.

Can you confirm if/when this fix has been made?

Thanks

Hi,

It is fixed, but with a slight modification:

Current offers documentation seems to have the incorrect dates format. Right now we are accepting 2 formats YYYY-MM-DD and YYYY-MM-DDThh:mm:ss , since it’s less confusing having only one format added only one. But really open to other opinions.

We have updated the documentation accordingly.

Doug

Thanks Doug - I’m still getting a syntax error. Can you tell if it’s something on my end?

Can you send me your query (minus keys, etc.?)

I grabbed this one from the docs, and just updated the Key, publisherId, BrandId and startDate.

This one worked.

Doug

curl -X POST  https://api.fidel.uk/v1/offers   -H 'content-type: application/json'  -H 'fidel-key: sk_test_xxxx'  -d '{       "countryCode": "GBR",    "name":"20% Off Netflix Subscription",
        "publisherId":"fec57ce7-d161-4c8f-8da0-1ebf841f4739",
        "brandId":"0b7b83a3-ccb3-4854-804a-90e5d951d1eb",
        "startDate":"2020-05-25T10:34:00",
        "type":{
          "name":"discount",
          "value":20
        }
      }'

var url = “https://api.fidel.uk/v1/offers”;

var offer = {​
countryCode: “USA”,​
name:“20% Off Everything”,​
brandId:“450fe546-33f2-4e80-81e0-9dbeb84986a8”,​
publisherId:“afc160d2-c4a1-4a17-89e6-de541ecd7e48”,​
startDate:“2020-04-10”,​
type:{​
name:“Super Sale”,​
value:20,​
}​
};​

const request = new Request(url, {​
method: ‘POST’,​
headers: new Headers({​
‘content-type’: ‘application/json’,​
‘fidel-key’: ‘xxxx’,​
}),​
body: JSON.stringify(offer),​
});​

fetch(request)​
.then(res => res.json())​
.then(res => console.log(res));

Hi @rknapp
The type:name field only allows 2 parameters: amount (for a total savings like $25 off) or percentage (25% off)

startDate:“2020-04-10”,​
type:{​
name:“Super Sale”,​
value:20,​
}​

You’ll need to change “super sale” to percentage (I am assuming percentage as the name of the offer is 20% off everything).

If you look at the devTools console log for your request - you can see the error:
image

Doug

That worked perfect - Thank you