Why am I (sometimes) getting a bad json error. Status code 400