Aircraft: B737
Phase of flight: Climb
Anomaly: ATC Issue All Types; Aircraft Equipment Problem Less Severe; Deviation - Track / Heading All Types; Deviation / Discrepancy - Procedural Published Material / Policy; Deviation / Discrepancy - Procedural Clearance

We received a CPDLC (Controller Pilot Data Link Communications) clearance indicating we were cleared via the ZZZZZ Departure climb via to 5;000 ft. with our squawk. Before departure; CPDLC aborted. We were not able to accept the clearance so we contacted Clearance Delivery. Upon communicating with Clearance Delivery; we told them our squawk and he said; squawk read-back correct with no correction to the ZZZZZ Departure. We were cleared for takeoff by the Tower; and handed off to Departure. After receiving a clearance to contact the next Departure Controller; we were told to 'climb via the departure' not what departure. If we were told to climb via the ZZZZZ1 Departure; we would have immediately realized there was a discrepancy in our clearance. Upon reaching 8;000 ft.; the Departure Controller told us to immediately turn to heading of 220 and maintain our current altitude which was 8;000 ft. He asked us what departure we were on because we should not be turning north. I told him we were on the ZZZZZ Departure; which we had received from the CPDLC (Controller Pilot Data Link Communications) Clearance and confirmed with Clearance Delivery. He indicated there was a note on the ZZZZZ Departure that it was not to be used after XA:00 local. Although the note was read; because we had received that clearance; we did not think of questioning it because we had already talked to Clearance Delivery. I did not understand the communication breakdown between ATC and our final clearance; but we were flying the clearance that we were given and filed on our flight plan. ZZZ is obviously a high density airport and they routinely have clearances read back with the squawk only. This could have easily been corrected if we would have been required to read back the route they expected us to fly. On the ground in ZZZ we received our clearance via CPDLC (Controller Pilot Data Link Communications); which cleared us via ZZZZZ; ZZZZZ2; then as filed; climb via except maintain 5;000 ft. However after receiving that; we lost ACARS COMM; which resulted in us losing our CPDLC connection. I attempted to log back into CPDLC but it wouldn't let me accept the clearance anymore; so I called Clearance; who asked if we were looking for our clearance; and I explained we received it on CPDLC but lost our connection and then read back just our squawk code; which is ZZZ's [procedure] on reading back clearances. We were told squawk read-back correct; and then asked our gate; we gave that and continued on our way. On departure; everything went normal; the Captain checked in with Departure and said our altitude and climbing via the ZZZZZ except to maintain 5;000 ft. [Departure] read back radar contact; climb via the SID. We set in the top altitude of 8;000 ft. and had VNAV set. As we were about to level off we were told to turn immediately to a 220 heading and maintain our current altitude; which was already about 8;000 ft. Both the Captain and I were expecting a traffic conflict because of how it was stated. The Controller; however; said he wasn't sure what departure we were flying but we shouldn't be heading north. He explained the ZZZZZ isn't used after XA:00 local time and we shouldn't be on it. We explained what our CPDLC had said; and he said no problem and provided us with radar vectors eventually to ZZZZZ3. The rest of the flight was uneventful. B737 Flight Crew reported ACARS failure and accepted bad clearance by Dispatch which was resolved by ATC during climb.